0

Trying to get the certain fields to display, ideally in a table (headings, rows & columns). And looking for a best way find fields in a Json feed. I tried using the controller to find the fields then pass that data to the view in the HTML.

Is there something wrong in the controller with respect to the Json? the fields are empty. Seems like nothing is passed from the controller to the view ? This is what I tried:

<!doctype html>
<html ng-app="app" >
<head>
    <meta charset="utf-8">
    <title>LIVE</title>
    <!-- <link rel="stylesheet" href="style.css"> -->
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js"></script>
    <script>
        var app = angular.module('app', []);

app.controller('DataCtrl', function ($scope, $http) {

 $scope.result = {
                  "data": {
                    "transactionList": [{
                      "barcode": "52905819992681",
                      "training": 0,
                      "tranNo": 1,
                      "userId": "8796093054980",
                      "retailerId": "defaultRetailer",
                      "storeId": "12Store",
                      "deviceId": "afd03463-9ee7-45d4-9d2e-8d64a683f126",
                      "tillId": "2",
                      "tranTypeId": "regularSale",
                      "isTranVoid": 0,
                      "totalItems": 1,
                      "merchTotal": 50.0,
                      "promoTotal": 0.0
                    }, {
                      "barcode": "52905819592681",
                      "training": 0,
                      "tranNo": 1,
                      "userId": "8796093054980",
                      "retailerId": "defaultRetailer",
                      "storeId": "23Store",
                      "deviceId": "afd03463-9ee7-45d4-9d2e-8d64a683f126",
                      "tillId": "2",
                      "tranTypeId": "regularSale",
                      "isTranVoid": 0,
                      "totalItems": 1,
                      "merchTotal": 50.0,
                      "promoTotal": 0.0
                    }]
                  }
                }

};

$scope.elements = $scope.result.data.transactionList.map(function (res) {
  var e = {};
  e.transTypeId = res.transTypeId;
  e.userId = res.userId;
  e.storeId = res.storeId;
  return e;
});

});

    </script>
</head>
<body ng-controller="DataCtrl">
<h1>Live from the JSON feed</h1>
<ul>
    <li ng-repeat="e in elements">
        {{ e.transTypeId}}: {{ e.userId }}, {{ e.storeId }}
    </li>
</ul>
</body>
</html>
0

4 Answers 4

2

You have a extra } in your $scope.result. It should be like:

$scope.result = {
                  "data": {
                    "transactionList": [{
                      "barcode": "52905819992681",
                      "training": 0,
                      "tranNo": 1,
                      "userId": "8796093054980",
                      "retailerId": "defaultRetailer",
                      "storeId": "12Store",
                      "deviceId": "afd03463-9ee7-45d4-9d2e-8d64a683f126",
                      "tillId": "2",
                      "tranTypeId": "regularSale",
                      "isTranVoid": 0,
                      "totalItems": 1,
                      "merchTotal": 50.0,
                      "promoTotal": 0.0
                    }, {
                      "barcode": "52905819592681",
                      "training": 0,
                      "tranNo": 1,
                      "userId": "8796093054980",
                      "retailerId": "defaultRetailer",
                      "storeId": "23Store",
                      "deviceId": "afd03463-9ee7-45d4-9d2e-8d64a683f126",
                      "tillId": "2",
                      "tranTypeId": "regularSale",
                      "isTranVoid": 0,
                      "totalItems": 1,
                      "merchTotal": 50.0,
                      "promoTotal": 0.0
                    }]
                  }
                };

// get rid of this};

Here is working plunkr

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

1 Comment

Thanks -- was getting lost with the }; and the }
1

Perhaps a }; too many?

Automatic indentation usually makes those kinds of errors apparent.

1 Comment

Thanks -- was getting lost with the }; and the }
0

Have you tried to use ng-model="...", it gives you the opportunity to overwrite an attribute or to show it. You can try it with

<input type="number" ng-model="someID" disabled="disabled">  

*disabled if u need readOnly on that field. and see how it works, maybe it can help you out. regards

Comments

0

I may be wrong, but you are trying to read json data directly without parsing it?
MDN JSON.parse()

Also it would be nice if you upload your code on something like http://jsfiddle.net This way people can test it out.

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.