Ok, seems that I was having too many issues with the way in which my Angular site is setup, so I put it in a plunker as then anyone can see it.
Original question: Angular retrieve specific data into $scope variable is not working
Plunker http://plnkr.co/edit/NsE29zjraQp9UeklJBiI?p=preview
My issues are 1. i'm not understanding how to use app.filter 2. Issue with app name 3. forEach with push inside $http.get throws error not defined
The plunker Index.html has the template code loop , app.module.js is root and the device.controller.js is where I'm using controller with $http.get call using json file to fake it.
I was attempting to use the other persons answer so this code
$scope.devices = result.data.Devices; // gives all data ...
Filter I was wondering if this with work
<div ng-repeat="device in devices">
{{ device.DeviceStatus }}
</div>
Then this code I'm not sure it in the correct "place"
seems like i'm not understanding "app"
app.filter('deviceStatus', function () {
return function (status_id) {
var statuses = ['Old Device', 'New Device', 'Activated', 'Unactivated'];
return statuses[status_id];
};
});
Example filter:
<td>{{device.DeviceId | deviceStatus}}</td>
Let me try to understand your issue.
As per your question, it seems that you have problems understanding what
app
is and how to usefilter
.This is the working version of your plunkr. Check this url
app
in your project is theng-app
directive. Theng-app
directive tells AngularJS that the element is the "owner" of an AngularJS application.$scope.statuses
which is not defined yet. So first define$scope.statuses
to be an empty array i.e `$scope.statuses = [];Hope this works for you!`