AngularJS :使用角度属性指令将元素包装到自定义模板中
AngularJS : Wrapping an element into a custom template with an angular attribute directive
>情况:
我有一个属性指令,将其元素包装到模板中。在这里:
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
不起作用
这是褶皱机
您可能遇到了一个可能的错误。这是一个优先级和指令处理顺序问题。将指令的优先级设置为比 ng 模型更高的优先级。使用 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>"
}
});
演示
相关文章:
- 如何在jQuery中包装两个元素的组
- 包装元素中的所有元素,直到出现特定标记
- 如何包装元素的所有子元素
- 如何使用链接包装元素覆盖它事件
- 当外部链接是内部的另一个链接时,外部链接不会包装元素
- jQuery中根据其数据属性包装元素的最佳方法是什么?
- 高阶组件和访问包装元素的子元素
- 使用jQuery包装元素组
- 使用jQuery包装元素
- 防止IE在contenteditables中包装P元素
- 在jQuery中选择包装元素
- 为什么使用jQuery元素包装元素要快得多?
- 如何在angular中使用数据绑定指令来包装元素
- 如何获取onclick包装元素的id
- 在包装元素中呈现更新的数据
- 单击iframe包装元素上的event
- 如何使用javascript在字符周围包装元素
- 如何在html字符串var中包装元素
- AngularJS组件可以修改它们的包装元素吗?
- 向传递给函数的jQuery包装元素添加元素