[英]AngularJS: Calling custom directives from within a custom directive doesn't seem to work
I have a plunker here that demostrates it . 我在这里有个小矮人可以说明这一点 。
I can create two directives. 我可以创建两个指令。 In this case one is named zMonthSelect, and the other is named zTest that references zMonthSelect. 在这种情况下,一个名为zMonthSelect,另一个名为zTest,它引用zMonthSelect。 Angular doesn't seem to like if they're nested. 如果它们嵌套,Angular似乎不喜欢。 Why is that? 这是为什么? What can I do to fix it? 我该如何解决?
Here's the code: 这是代码:
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) {
}
};
});
and the HTML: 和HTML:
<body ng-controller="MainCtrl">
zTest: <z-test></z-test><br/>
zMonthSelect: <z-month-select></z-month-select><br/>
</body>
You have a mismatch in your directive name. 您的指令名称不匹配。 In the zTest
directive you're trying to use <z-month-list>
, but your directive is named zMonthSelect
. 在zTest
指令中,您尝试使用<z-month-list>
,但是您的指令名为zMonthSelect
。 Just change your zTest
directive to us <z-month-select>
. 只需将您的zTest
指令更改为我们<z-month-select>
。 See http://plnkr.co/edit/x2i8lv?p=preview 看到http://plnkr.co/edit/x2i8lv?p=preview
Or you can rename your inner directive to zMonthList
. 或者,您可以将内部指令重命名为zMonthList
。 See http://plnkr.co/edit/aQlSqK?p=preview 看到http://plnkr.co/edit/aQlSqK?p=preview
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.