【发布时间】:2013-12-09 12:26:11
【问题描述】:
我有两个指令:
// Generated by CoffeeScript 1.6.3
app.directive("focusMe", function() {
return {
scope: {
focus: "=focusMe"
},
link: function(scope, element) {
return scope.$watch("focus", function(value) {
if (value === true) {
element[0].focus();
return scope.focus = false;
}
});
}
};
});
和:
// Generated by CoffeeScript 1.6.3
app.directive("cleanMe", function() {
return {
scope: {
clean: "=cleanMe"
},
link: function(scope, element) {
return scope.$watch("clean", function(value) {
if (value === true) {
element[0].value = "";
return scope.clean = false;
}
});
}
};
});
这个输入(angularUI):
<input type="text" ng-model="addUserSelected" typeahead="emp.value for emp in allUsers | filter:$viewValue | limitTo:5" typeahead-editable="false" typeahead-on-select="addLine($item.id)" focus-me="usersFocusInput" clean-me="usersCleanInput">
我收到此错误:
Error: [$compile:multidir] http://errors.angularjs.org/1.2.3/$compile/multidir?p0=cleanMe&p1=focusMe&p…2%20focus-me%3D%22usersFocusInput%22%20clean-me%3D%22usersCleanInput%22%3E
我做错了什么?
如果我从 html 中删除 clean-me 属性,它会起作用。
谢谢
【问题讨论】:
-
为什么不重置
ng-model绑定的模型?我怀疑你不需要cleanMe指令 -
cleanMe 没有意义,它可以是任何 2 个(或更多)指令。 clean-me 和 focus-me 仅用于示例。
标签: javascript angularjs angularjs-directive