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
Dinesh KumarAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Neeraj SoniSr. ArchitectCommented:
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>
Neeraj SoniSr. ArchitectCommented:
This is a similar example with few values:


<body ng-app="myApp" ng-controller="myCtrl">
    <table >
      <tr ng-repeat="key in cities">
        <td>{{key.city}}</td>
        <td>{{key.country}}</td>
      </tr>
    </table>
</body>


var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
  $scope.cities = [{
    city: "NewDelhi",country:"India"
  }, {
    city: "Londan",country:"UK"
  }, {
    city: "NewYork",country:"USA"
  }, {
     city: "Tokyo",country:"Japan"
  }, {
     city: "Moscow",country:"Russia"
  }, {
     city: "Beijing ",country:"China"
  }, {
    city: "New Delhi",country:"India"
  }];
});

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Dinesh KumarAuthor Commented:
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 :)
Neeraj SoniSr. ArchitectCommented:
Good to know it helped :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.