angularBeginner angularBeginner - 1 year ago 241
JSON Question

AngularJs: Convert json string to html table

I am an absolute newbie to angularjs and i have been making my hands dirty from the past 3 days. Now, the requirement is to convert a json string from the rest end point to tabular data. Here is the code i am trying.

$scope.getDataCatalogue = function(){

.success(function(data, status, headers, config){
//do something with your response
$scope = data;
console.log("not world");

$scope.getDataCatalogue = function(){

Now,how can i convert the json to grid from the data. Is this the right way to approach the problem.

Answer Source

If you have a fixed structure coming out of the data then you can simply make use of ng-repeat to iterate through the object(data) and display it on your pre-created table. Fiddle

Example shown below:

Considering this is your object which your assigning to a $scope variable name people. $scope.people = data;

      id: 1,
      firstName: "Peter",
      lastName: "Jhons"
      id: 2,
      firstName: "David",
      lastName: "Bowie"

In your controller:

.success(function(data, status) {
    $scope.people = data;

In your HTML :

        <th>First Name</th>
        <th>Last Name</th>
    <tr ng-repeat="person in people">
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download