Link to home
Start Free TrialLog in
Avatar of Dinesh Kumar
Dinesh KumarFlag for India

asked on

ng-repeat angular

Experts!

function storeController($scope, $routeParams, DataService) {
$scope.productsNew = '[{"id":3,"sku":"APL","name":"Apple","description":"Eat one every day to keep the doctor away!","price":20},{"id":4,"sku":"BAN","name":"Banana","description":"These are rich in Potassium and easy to peel.","price":40}]';
}

Open in new window


I want to show these values in table using ng-repeat

how can I do it in angular, please help

Thanks
meetDinesh
Avatar of Neeraj Soni
Neeraj Soni
Flag of India image

You might try something like this:


<body ng-app="myApp" ng-controller="myController">
...
...
<table >
      <tr ng-repeat="p in productsNew">
        <td>{{p.id}}</td>
        <td>{{p.sku}}</td>
...
...
      </tr>
    </table>
ASKER CERTIFIED SOLUTION
Avatar of Neeraj Soni
Neeraj Soni
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Dinesh Kumar

ASKER

Thanks you so much Neeraj for helping me out there.. I was struggling with it for last 3 days..

and I see json array should not be initialized like following:

$scope.productsNew = '[{"id":3,"sku":"APL","name":"Apple","description":"Eat one every day to keep the doctor away!","price":20},{"id":4,"sku":"BAN","name":"Banana","description":"These are rich in Potassium and easy to peel.","price":40}]';

It generated error so I removed single quotes so its only

$scope.productsNew = [{"id":3,"sku":"APL","name":"Apple","description":"Eat one every day to keep the doctor away!","price":20},{"id":4,"sku":"BAN","name":"Banana","description":"These are rich in Potassium and easy to peel.","price":40}];

and it worked perfectly.

Inspiration taken from your solution :)
Good to know it helped :)