我有以下带有自定义指令“my-repeater”的代码:
<div ng-controller="AngularCtrl">
<div my-repeater='{{items}}'>Click here</div>
</div>
这是我的自定义指令:
myApp.directive('myRepeater', function($compile) {
return {
restrict: 'A',
link: function(scope, element, attrs) {
var myTemplate = "<div ng-click='updateRating({{item}});' ng-class='getRatingClass({{rating}});'>{{rating}}</div>";
var items = scope.items;
console.log('length: ' + items.length);
for (var i = 0; i < items.length; i++) {
var child = scope.$new(true);
console.log(items[i].ratings);
child.item = items[i];
child.rating = items[i].ratings;
var text = $compile(myTemplate)(child);
element.append(text);
}
}
};
});
ng-click和ng-class绑定在我的自定义指令中没有正确发生。谁能帮我解决我在这里做错的事情?
这是 JS 小提琴。 http://jsfiddle.net/JSWorld/4Yrth/5/