我可以创建两个指令。在这种情况下,一个名为 zMonthSelect,另一个名为 zTest,它引用 zMonthSelect。如果它们是嵌套的,Angular 似乎不喜欢。这是为什么?我能做些什么来修复它?
这是代码:
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
});
app.directive('zMonthSelect', function () {
return {
restrict: 'E',
priority: 1000,
scope: {
month: '=month'
},
template: '<select ng-model="month">' +
'<option value="1">Jan</option>' +
'<option value="2">Feb</option>' +
'<option value="3">Mar</option>' +
'<option value="4">Apr</option>' +
'<option value="5">May</option>' +
'<option value="6">Jun</option>' +
'<option value="7">Jul</option>' +
'<option value="8">Aug</option>' +
'<option value="9">Sep</option>' +
'<option value="10">Oct</option>' +
'<option value="11">Nov</option>' +
'<option value="12">Dec</option>' +
'</select>',
controller: function($scope) {
}
};
});
app.directive('zTest', function(){
return {
restrict: 'E',
priority: 1,
scope: {},
template: 'Test: <z-month-list month="1"></z-month-list>',
controller: function($scope) {
}
};
});
和 HTML:
<body ng-controller="MainCtrl">
zTest: <z-test></z-test><br/>
zMonthSelect: <z-month-select></z-month-select><br/>
</body>