0

I have an API that fetches data from database. My database contains such as this values

ID Name 1 Body 2 Skin 3 Fat

I have an API that correctly fetches this. I display it on the table but then, the displayed value for example; if the value that is correct is number 1, the name that will be displayed on the UI is "Skin" instead of "Body" what could be the problem?

I have this on my controller

Service.fetchType()
            .then(function(data){

                $scope.type= data.data;
                localStorage.Type = JSON.stringify(data.data);
            }
        );

And only uses ng-repeat and {{item.Type}} on my html file

<tr ng-repeat=" item in Type >
  <td> {{ item.type}}   </td>
</tr>
8
  • 1
    give some code of html and controller... this is because array starts at index 0.. but i need to see wat u hv done Commented Mar 28, 2017 at 5:23
  • give $scope.Type and Ng repeat also Commented Mar 28, 2017 at 5:31
  • @bleykFaust: Add your data format. Commented Mar 28, 2017 at 5:31
  • @MuhammedNeswine what data format? Commented Mar 28, 2017 at 5:39
  • @bleykFaust: 'data.data' value Commented Mar 28, 2017 at 5:39

1 Answer 1

0

Hope you have Json string as : [{"ID" :1, "Name":"Body" },{"ID" :2, "Name":"Skin" },{"ID" :3, "Name":"Fat" }] and following works perfect. You can skip last line to convert json string to object.

var app = angular.module('myApp', []);
app.controller('appCtrl', function($scope, $location) {
    $scope.type= [{"ID" :1, "Name":"Body" },{"ID" :2, "Name":"Skin" },{"ID" :3, "Name":"Fat" }];  
//$scope.type = angular.fromJson(Json);
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.22/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<div ng-app="myApp" ng-controller="appCtrl">
<table>
<tr ng-repeat="item in type" >
  <td> {{ item.ID}}   </td>
 <td> {{ item.Name}}   </td>
</tr>
</table>
</div>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.