我觉得我错过了Angular指令的基本概念。嵌套指令和NgModel
参照此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
谈到了取代:真将使此代码工作。但是,我丢失了父模板的样式说明。 I.E:类窗体控件未合并到select元素上。
什么是使这项工作的角度方式?
啊..我明白了。所以,ng-model也会合并到模板中。优秀。非常感谢! – Ken