class 名称的输出数组到元素 ng-repeat
output array of class names on to element ng-repeat
我有一个 class 名称数组,我想附加到一个元素,例如..
Tags = [tag1, tag2, tag3] ;
<article ng-class="tag1, tag2, tag3"></article>
有什么方法可以在 ng-class 上使用 for 循环将此数组输出到元素上..
谢谢
ng-class 可以获取数组本身,因此只要 Tags
是您可以执行的范围的 属性:-
<article ng-class="Tags"></article>
Expression to eval. The result of the evaluation can be a string representing space delimited class names, an array, or a map of class names to boolean values. In the case of a map, the names of the properties whose values are truthy will be added as css classes to the element.
演示
angular.module('app', []).controller('ctrl', function($scope){
$scope.Tags = ['tag1', 'tag2', 'tag3'];
});
.tag1.tag2.tag3{
color:blue;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="ctrl">
<article ng-class="Tags">Article</article>
</div>
我有一个 class 名称数组,我想附加到一个元素,例如..
Tags = [tag1, tag2, tag3] ;
<article ng-class="tag1, tag2, tag3"></article>
有什么方法可以在 ng-class 上使用 for 循环将此数组输出到元素上..
谢谢
ng-class 可以获取数组本身,因此只要 Tags
是您可以执行的范围的 属性:-
<article ng-class="Tags"></article>
Expression to eval. The result of the evaluation can be a string representing space delimited class names, an array, or a map of class names to boolean values. In the case of a map, the names of the properties whose values are truthy will be added as css classes to the element.
演示
angular.module('app', []).controller('ctrl', function($scope){
$scope.Tags = ['tag1', 'tag2', 'tag3'];
});
.tag1.tag2.tag3{
color:blue;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="ctrl">
<article ng-class="Tags">Article</article>
</div>