javascript - Cannot pass array to angular directive -
cannot pass array input mask plugin in angular. maybe can me this.
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'}" />
the attribute value return string , not object needed pass plugin
you can switch quotes around string valid json , parse json object
<input type="text" input-mask='{"mask": "9{4} 9{4} 9{4} 9{4}[9]", "autounmask": "true"}' />
js
.directive('inputmask', function() { return { restrict: 'a', scope: { inputmask: '@' }, link: function(scope, el, attrs) { var mask =json.parse(attrs.inputmask); $(el).inputmask(mask); } }; })
but realistically simpler not putting string in html , passing object reference controller isolated scope instead
Comments
Post a Comment