我試圖使用輸入掩碼jQuery plugin作爲指令,但在Chrome的控制檯錯誤中出現以下錯誤。將jQuery插件轉換爲AngularJS指令
TypeError: Cannot read property 'length' of undefined
我的代碼
JS
var app = angular.module('app', ['ngResource']);
app.directive('inputMask', function(){
return {
restrict: 'A',
link: function(scope, element){
element.mask();
}
}
})
HTML
<input type="text" class="form-control input-mask" data-input-mask data-mask="{mask: 00/00/0000}" placeholder="eg: 23/05/2014">
http://plnkr.co/edit/Kp3SYS0cbIfVm1gTwtE0?p=preview
請幫我解決這個問題。
使用已經創建的指令,而不是創建自己的http://angular-ui.github.io/ui-utils/ –