我想以角度扩展文本类型的输入,这样在用户输入一些文本后,文本值通过自定义过滤器传递,该过滤器在输入输入时进行一些净化,这是我到现在为止的内容,但我是收到错误:
angular.js:13920 TypeError: Cannot read property 'length' of undefined
at addDirective (http://bank.com:4000/vendor/bower_components/angular/angular.js:9495:35)
at collectDirectives (http://bank.com:4000/vendor/bower_components/angular/angular.js:8677:11)
at compileNodes (http://bank.com:4000/vendor/bower_components/angular/angular.js:8539:22)
这是我写的:
angular.module('app').config(extendInputDirective);
function extendInputDirective($provide) {
$provide.decorator('inputDirective', function($delegate, $filter) {
debugger;
var directive = $delegate[0];
var link = directive.link;
directive.compile = function() {
return function(scope,element, attrs, ngModel) {
debugger;
if(attrs.type === 'text') {
ngModel.$parsers.unshift(function(viewValue) {
var value = $filter('pArabicCharFilter')(viewValue);
return value;
});
}
link.apply(this, arguments);
}
}
});