AngularJS模式中的jQuery掩码

时间:2017-12-15 18:26:23

标签: jquery angularjs modal-dialog mask

我在here范围之外使用jQuery掩码,如下所示:

$("#input").mask("(00) 00000-0000");

当我尝试在我的模态控制器中使用它时,它不起作用。

有人对此有解释吗?

控制器代码:

$scope.modal = function (cl) {
    ModalService.showModal({
        templateUrl: 'modal.html',
        inputs: {
            x: x
        },
        controller: function ($scope, close, x) {

            $("#input2").mask("(00) 00000-0000");

            $scope.close = function (op) {
                //doSomething...
            };
        },
        controllerAs: "ModalController"
    }).then(function (modal) {
        modal.element.modal();
        modal.close.then(function (result) {
            //doSomething...
        });
    });
};  

1 个答案:

答案 0 :(得分:1)

考虑使用UI-MASK

angular.module("app",['ui.mask'])
<script src="//unpkg.com/angular/angular.js"></script>
<script src="//unpkg.com/angular-ui-mask/dist/mask.js"></script>
  <body ng-app="app">
    <input type="text" ng-model="phonenumber"
           ui-mask="(99) 99999-9999"  ui-mask-placeholder 
           ui-mask-placeholder-char="_" />
    <br>
    Number= {{phonenumber}}
  </body>