Adit choudhary
Adit choudhary

Reputation: 109

ng-repeat on object having array in angularjs

I'm using angularjs, Below is my code and I need output as

red

green

yellow

It is displaying as an array

['red','green','yellow']

Please help.

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"> 
</script>

<body ng-app="myApp" ng-controller="myCtrl">

    <div ng-repeat="product in products | filter: { color: true }">
       {{product.type}}
     </div>
</body>
var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
      $scope.products = [
   { id: 1, name: 'test', color: true, type:['red','green','yellow'] },
   { id: 2, name: 'bob', color: false },
   { id: 3, name: 'john', color: false },
   { id: 4, name: 'rock', color: false },
   { id: 5, name: 'mercy', color: false },
   { id: 6, name: 'jack', color: false }
  ];
});

Please help

Upvotes: 0

Views: 42

Answers (1)

Adit choudhary
Adit choudhary

Reputation: 109

**Thanks i got answer, if any good alternative. please share **

<div ng-repeat="product in products | filter: { color: true }">

     <div ng-repeat ="type in product.type">
     {{type}}
      </div>


</div>

Upvotes: 6

Related Questions