angular——事件监听 $watch

<!-------------------- 输入框按钮组 ----------------------->
        <section class="common_input_button_style top_10">
            <label class="item item-input">
                <i class="icon ion-android-phone-portrait placeholder-icon"></i>
                <input type="tel" placeholder="请输入手机号码" autofocus ng-model="data.phoneNumber">
            </label>
            <div class="common_button">
                <button class="button button-block button-calm" ng-disabled="data.disabled"
                        ng-click="action.toSendVerifyMessagePage()">下一步
                </button>
            </div>
        </section>

*监听<input type="tel" placeholder="请输入手机号码" autofocus ng-model="data.phoneNumber">输入框中文本的变化。

angular.module('MrTrustApp.controllers')

    .controller('AuthLoginRegisterCtrl', function ($scope, StateGo, $ionicPopup) {

            //定义数据
            $scope.data = {};
            $scope.data.phoneNumber = '17789763630';
            
            //匹配手机号码成功,则按钮可用
            $scope.$watch('data.phoneNumber', function (newVal, oldVal) {

                <!--TODO: 正则匹配 各种 电话号码   -->

                if (/\d{11}/.test(newVal)) {
                    $scope.data.disabled = false;
                } else {
                    $scope.data.disabled = true;
                }

            });
   });
 

 

posted @ 2016-04-19 23:27  四叶草Clover  阅读(2128)  评论(0编辑  收藏  举报