我创建了两个指令:List和Entry。 List获取一个数组作为属性,并为每个数组成员显示一个Entry。
列表指令:
app.directive('list', function() {
var directive = {};
directive.restrict = 'E';
directive.scope = {};
directive.scope.listArray= '=';
directive.template = '<ul id="list">' +
'<track-element ng-repeat="entry in listArray" entry="entry" onSelect="onSelectEntry()"></track-element>' +
'</ul>';
directive.link = function(scope, iElement, iAttrs) {
scope.onSelectEntry = function() {
alert("hi");
};
};
return directive;
});
入境指令:
app.directive('entry', function() {
var directive = {};
directive.restrict = 'E';
directive.scope = {};
directive.scope.entry= '=';
directive.scope.onSelect = '&';
directive.template = '<li class="entry" data-index="{{entry.ID}}" ng-click="onSelect()">' +
'<p>{{entry.content}}</p>' +
'</li>';
return directive;
});
我将一个函数onSelectEntry
从list指令传递给entry指令。如果单击,则应执行此功能。
但是这个函数永远不会被执行。有什么想法吗?