【发布时间】:2015-11-11 20:30:36
【问题描述】:
我觉得我缺少 Angular 指令的基本概念。
参考此 Plnkr:http://plnkr.co/edit/WWp9lB6OvxHL8gyBSU5b?p=preview
我有一个模型:
{
message: string,
value: number
}
我有一个 itemEditor 指令来编辑该模型:
.directive('itemEditor', function() {
return {
replace: true,
templateUrl: 'item.editor.html',
require: 'ngModel',
model: {
item: '=ngModel'
}
};
})
但我想将值的编辑委托给自定义控件:
.directive('valuePicker', function() {
return {
replace: true, // comment this to make it work
templateUrl: 'value.picker.html',
require: 'ngModel',
scope: {
ngModel: '='
},
controller: Controller
};
function Controller($scope, Values) {
$scope.values = Values;
console.log({scope:$scope});
}
})
目前,此代码给出错误:
Error: $compile:multidir
Multiple Directive Resource Contention
评论 replace: true 将允许此代码工作。但是,我丢失了父模板中的样式说明。 IE:类 form-control 没有合并到选择元素上。
实现这项工作的角度方式是什么?
【问题讨论】:
标签: angularjs angularjs-directive