我将以下指令添加到我的视图(在html中)中的angularjs中,似乎可以在控制台上看到console.log,但是,没有添加类'subPlaylistSecondaryItemRemoval'。
我的HTML
<ul class="dupeAssets" first-element-list>
<li ng-repeat="dupeAssetslist in playlistAssets.assets track by $index" ng-if="dupeAssetslist.type == 'Playlist'">{{dupeAssetslist.title}}</li>
</ul>
我的指令在
之下 appModule.directive("firstElementList", function () {
console.log("firstElementList");
return {
restrict: "A",
link: function (scope, element, attributes) {
$scope.$watch(element.children(), function () {
var children = element.children();
for (var i = 1; i < children.length; i++) {
if (children[i].nodeType !== 8) {
angular.element(children[i]).addClass('subPlaylistSecondaryItemRemoval');
}
}
});
}
};
});
但是,我收到以下错误
angular.js:12783 ReferenceError: $scope is not defined
请帮忙吗?
答案 0 :(得分:0)
link: function (scope, element, attributes) {
应该是:
link: function ($scope, element, attributes) {
答案 1 :(得分:0)
working fiddel https://jsfiddle.net/U3pVM/25262/
这个fiddel使用角度1.0.3,所以我按索引删除了跟踪