【发布时间】:2013-05-25 16:16:24
【问题描述】:
我正在尝试有条件地更改嵌套在无序列表中的元素的类。
当不使用ng-repeat创建列表时,我可以使用jqlite选择器.children()找到正确的元素并更改类。
但是我使用ng-repeat 创建列表,但我不知道如何访问我想要的特定列表元素。 .children() 总是返回 undefined。
这是我正在尝试做的一个 jsfiddle http://jsfiddle.net/whitehead1415/ENtTC/3/
app.directive('myDirective1', function () {
return {
restrict: 'A',
link: function ($scope, element, attrs, controller) {
//for some reason element.children()[0] is undefined
//why? what can I do about it?
angular.element(element.children()[0]).css('background', 'grey')
}
};
});
我需要能够根据两件事改变班级
- 当用户点击特定元素时,该元素需要突出显示
- 当用户单击一个按钮时,下一个元素将被突出显示(该按钮不包含在 jsfiddle 中)
我曾考虑将指令放在每个列表元素上,但唯一的问题是我不知道如何让它们都相互了解,因此一次只突出显示一个元素
【问题讨论】:
标签: javascript html angularjs angularjs-directive angularjs-ng-repeat