angular——事件监听 $watch

主宰稳场 提交于 2020-02-04 21:39:44
<!-------------------- 输入框按钮组 ----------------------->
        <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;
                }

            });
   });
 

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!