Angularjs 使用ng repeat指定随机样式值

Angularjs 使用ng repeat指定随机样式值,angularjs,Angularjs,Im使用$http调用提取用户列表,我会在一个div中显示每个用户的随机名称,如下所示: <div class="circle colorxxx x6" style="top:197px;left:168px;width:110px;height: 110px"></div> 对于每个div,我将随机更改样式值top、left width和height。怎么可能?我看到了ng类偶数和奇数的用法,但对于许多结果,我有重叠div 您可以使用ng repeat和ng clas

Im使用$http调用提取用户列表,我会在一个div中显示每个用户的随机名称,如下所示:

<div class="circle colorxxx x6" style="top:197px;left:168px;width:110px;height: 110px"></div>

对于每个div,我将随机更改样式值top、left width和height。怎么可能?我看到了ng类偶数和奇数的用法,但对于许多结果,我有重叠div

您可以使用ng repeat和ng class来获取随机值,您应该使用控制器中的函数来生成随机类。对于div,您可以同时使用ng class和class。将所有div中应包含的值放入class属性,将随机值放入ng class属性:

HTML:


random出现错误,这是我的控制器:

$scope.getRandomClass = function() {
    // Generate random string to set as class
}
var myShows = ['fucsia x1','violetto x2','celeste x3','arancio x4','rosso x5'];
    $scope.getRandomClass = function() {
        return myShows[Math.floor(Math.random() * myShows.length)];
    }
    $http.post('http://www.mimanchitu.it/ap/include/user_rand.asp')
    .success(function(ut){$scope.uts = ut;})
    .error(function(){alert("Errore di connessione!")})
这是我的模板:

<div ng-repeat="ut in uts" style="background-image:url({{ut.avatar}})" class="circle" ng-class="getRandomClass()"><a href="#/app/showprof/{{ut.id}}/" class="secondary-content">{{ut.name}}</a></div>

错误是error Reference/$rootScope/infdig为什么

好主意的可能复制品。。。。我不太熟悉随机获取。。。。像是什么$scope.getRandomClass=函数{var show=myShows[Math.floorMath.random*myShows.length];}类似的东西正是我的目标。
<div ng-repeat="ut in uts" style="background-image:url({{ut.avatar}})" class="circle" ng-class="getRandomClass()"><a href="#/app/showprof/{{ut.id}}/" class="secondary-content">{{ut.name}}</a></div>