提前谢谢你!我添加了自定义指令来呈现电话号码格式的字段。它工作得很好,直到gulp缩小js文件。之后它抛出错误**[$injector:unpr]未知提供程序:eProvider〈- e〈- phoneInputDirective**是在某个地方注册指令的特殊方法吗?我不确定是怎么回事。请帮助。
careApp.directive('phoneInput', function ($filter, $browser) {
return {
require: 'ngModel',
link: function ($scope, $element, $attrs, ngModelCtrl) {
var listener = function () {
var value = $element.val().replace(/[^0-9]/g, '');
$element.val($filter('tel')(value, false));
};
// This runs when we update the text field
ngModelCtrl.$parsers.push(function (viewValue) {
return viewValue.replace(/[^0-9]/g, '').slice(0, 10);
});
// This runs when the model gets updated on the scope directly and keeps our view in sync
ngModelCtrl.$render = function () {
$element.val($filter('tel')(ngModelCtrl.$viewValue, false));
};
$element.bind('change', listener);
$element.bind('keydown', function (event) {
var key = event.keyCode;
// If the keys include the CTRL, SHIFT, ALT, or META keys, or the arrow keys, do nothing.
// This lets us support copy and paste too
if (key == 91 || (15 < key && key < 19) || (37 <= key && key <= 40)) {
return;
}
$browser.defer(listener); // Have to do this or changes don't get picked up properly
});
$element.bind('paste cut', function () {
$browser.defer(listener);
});
}
};
});
careApp.filter('tel', function () {
return function (tel) {
if (!tel) { return ''; }
var value = tel.toString().trim().replace(/^\+/, '');
if (value.match(/[^0-9]/)) {
return tel;
}
var country, city, number;
switch (value.length) {
case 1:
case 2:
case 3:
city = value;
break;
default:
city = value.slice(0, 3);
number = value.slice(3);
}
if (number) {
if (number.length > 3) {
number = number.slice(0, 3) + '-' + number.slice(3, 7);
}
else {
number = number;
}
return ("(" + city + ") " + number).trim();
}
else {
return city;
}
};
});
1条答案
按热度按时间u7up0aaq1#
我解决了这个问题。问题是依赖注入。在指令声明中,依赖应该在[]括号中的函数之前。在我的例子中,它是:您可以使用以下方法来创建一个新的应用程序: