1

I want to use a scope attribute of a directive as the class name in ngClass

someModule.directive("someDirective", function () {
    return {
        restrict: "A",
        scope: {
            styleClass: '@',
        },
        replace: true,
        template: "<li ng-class='{'{{styleClass}}:true'}' />"
    }
}

I've tried other syntax of ngClass as well but this doesn't work either (I added a $scope.dummy = true for this)

template: "<li ng-class=\"{true: '{{styleClass}}'}[dummy]\" />"

Is there a right way of doing this ??

4

1 回答 1

1

如果您的 ng-class 表达式中没有条件,您可以简单地在模板中使用 class:

template: "<li class='{{styleClass}}'/>"

这是 plunkr 中的一个示例:http ://plnkr.co/edit/YrqMeAIbaekeH8PFlQIg?p=preview

于 2014-06-18T09:15:20.463 回答