我正在尝试有条件地更改嵌套在无序列表中的元素的类。
当不使用ng-repeat
创建列表时,我可以使用 jqlite 选择器.children()
找到正确的元素并更改类。
但是,我正在使用ng-repeat
创建列表,但不知道如何访问我想要的特定列表元素。.children()
总是返回未定义。
这是我正在尝试做的事情的一个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 中)
我考虑过将指令放在每个列表元素上,但唯一的问题是我不知道如何让它们都相互了解,所以一次只突出显示一个元素