简体   繁体   English

根据属性值angularJs将Class添加到特定列表项

[英]Add a Class to specific list item based on attribute value angularJs

Here is my code that i am struggling with: 这是我正在努力的代码:

.directive('mydirective', function() {
    return {
        template: '<ul>\
        <li priority="500"><a href="#"><i></i>Inbox</a></li>\
        <li priority="500"><a href="#"><i></i>Language</a></li>\
        <li priority="1000"><a href="#"><i></i>Settings</a></li>\
        <li priority="500"><a href="#"><i></i>Contact</a></li>\
        <li priority="1000"><a href="#"><i></i>Help</a></li>\
        </ul>',
        link: function(v, e, a){
            var elm = e[0].childNodes[0].children;
        }
    }
});

All i want to do is to add a class to list items that have let say the priority= 1000. I am able to get the element but when i do the loop i don't know how to filter the attribute so then i can add the class. 我要做的就是添加一个类来列出可以说priority = 1000的项目。我能够获取元素,但是当我执行循环时,我不知道如何过滤属性,因此我可以添加班级。 Anyone came around this? 有人来过这个吗?

Thanks 谢谢

如果您要发送数据并使用ng-repeat,则应该可以使用

ng-class="{'className': data.priority === 1000}"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM