我有一个属性指令,它将元素包装到模板中。这是:
app.directive("myCustomInput", function(){
return{
restrict: "A",
replace: true,
scope:{},
transclude: "element",
template: "<div class='input-wrap'>"+
"<div ng-transclude></div>"+
"<i class='glyphicon glyphicon-chevron-down'></i>"+
"</div>"
}
});
我用它像:
<input my-custom-input ng-model="data.input" type="text" />
ng-model
不起作用
以下是plunker
答案 0 :(得分:1)
您可能遇到过可能的错误。它是优先级和指令处理订单问题。设置指令的优先级高于ng-model。使用1.2 v时,ng-model的默认优先级为0
,1.3版本ng-model
的优先级为1
。因此,让你的指令比ng-model具有更高的优先级,以便在指令呈现之前ng-model
处理输入之前发生指令和转换。
.directive("myCustomInput", function(){
return{
restrict: "A",
replace: true,
scope:{},
priority: 1, //Here set the priority
transclude: "element",
template: "<div class='input-wrap'>"+
"<div ng-transclude></div>"+
"<i class='glyphicon glyphicon-chevron-down'></i>"+
"</div>"
}
});
<强> Demo 强>