对于以下 angularjs 指令:
app = angular.module('ngApp');
app.value('objects', [
{id: 1, name: 'Jane Doe', active: true},
{id: 2, name: 'Test Biz', active: false},
{id: 3, name: 'Another Business', active: false}
]);
app.directive('myDirective', function (objects) {
return {
template: '<ul></ul>',
replace: true,
compile: function(element, attrs) {
for(var i=0;i<objects.length;i++) {
element.append('<div other-directive object={{object}}></div>');
}
}
};
})
.directive('otherDirecctive', function() {
return {
template: '<li>{{object.name}}',
replace: true,
scope: { object: '=' }
});
还有这段html:
<div my-directive></div>
如何将每个对象传递到子指令中?有没有更好的整体方式来构建这段代码?