Repeat internal attribute with Angular

I have a simple string array that represents classes:

var myApp = angular.module('myApp',[]); function MyCtrl($scope) { $scope.classes = ["one","two","three","four"]; } 

I would like to bind them inside the class attribute of a single element as such:

 <div ng-controller="MyCtrl"> <div ng-repeat="class in classes" class="{{class}}"></div> </div> 

And follow these steps:

 <div class="one two three four"></div> 

I can not find a resource that explains how to do this. The above code generates:

 <div class="one"></div> 

How to repeat an INSIDE element using ng-repeat ?

http://jsfiddle.net/Lvc0u55v/788/

+5
source share
1 answer

You do not need ng-repeat , just an ng-class that accepts an array as input.

 <div ng-class="classes"></div> 

https://docs.angularjs.org/api/ng/directive/ngClass

+5
source

Source: https://habr.com/ru/post/1244621/


All Articles