angularjs - How to use a variable inside the ng-repeat? -


i'm using ng-repeat list products, , want print out star symbol x times depending on product.rating. so, code looks following:

<p class="bs-rating"><i class="fa fa-star" ng-repeat="i in getrating({{ product.rating }}) track $index"></i></p>  

however, parsed product.rating string: error: [$parse:syntax] http://errors.angularjs.org/1.3.0-beta.8/$parse/syntax?p0=product.rating&p1=is

i have tried remove curly brackets, {{ }}:

<p class="bs-rating"><i class="fa fa-star" ng-repeat="i in getrating(product.rating) track $index"></i></p>  

it gave me undefined. getrating() declared following:

$scope.getrating = function(rating){     return new array(parseint(rating)); } 

could me figure out how pass variable ng tag?

the problem on getrating function ie on generating array. have developed alternative solution on link rating using ng-repeat @jsfiddle

<div ng-app="myapp" ng-controller="myctrl"> <ol>     <li ng-repeat="product in products">         {{product.name}}          (         <span style="font-weight:bold" ng-repeat="i in            getrating(product.rating)">             x         </span>         )     </li> </ol> 

var myapp = angular.module("myapp", []); myapp.controller("myctrl", function($scope){     $scope.products = [         {name : "product1", rating:3},         {name : "product2", rating:5},         {name : "product3", rating:1}         ];     $scope.getrating = function(rating){         var ratingarray = [];         (var = 1; <= rating; i++) {             ratingarray.push(i);         }         return ratingarray;     }; }); 

hopefully help. cheers


Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -