我覺得我錯過了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