【发布时间】:2016-02-05 15:04:24
【问题描述】:
无法将数组传递给 Angular 中的输入掩码插件。 也许有人可以帮我解决这个问题。
angular.module('myproject.directives').
directive('inputMask', function() {
return {
restrict: 'A',
scope: {
inputMask: '@'
},
link: function(scope, el, attrs) {
$(el).inputmask(attrs.inputMask);
}
};
});
<input type="text" input-mask="{'mask': '9{4} 9{4} 9{4} 9{4}[9]', 'autoUnmask': 'true'}" />
【问题讨论】:
-
问题可能是单引号。
-
'@' 属性告诉指令需要一个字符串,因此您可以将一个字符串传递给它,然后将其操作到一个数组中,该数组在链接函数中指令可以理解。不过,您在
input-mask属性中显示的内容看起来不像一个数组。
标签: javascript angularjs angularjs-scope directive input-mask