I am trying to display a table with items from JSON data. I have created a Service that returns the JSON data. In my controller, I am querying the Service to receive an array of data. It's a little confusing because I am putting the response in a new JavaScript variable and then placing that JS variable in a scope variable. I am using the scope variable in the ngRepeat directive in my HTML file to display the data in the table, but it is not showing up as expected.
Service:
myApp.factory('MyService', function ($resource) {
return $resource('data/mydata.json');
});
Controller:
var MyData = MyService.query(function () {
$log.info('[Result:]', MyData); // console shows the expected data
});
$scope.datas = MyData;
$log.info('Result2:', $scope.datas); // console shows an empty array
View:
<tr ng-repeat="item in filteredData = (datas | filter:search)>
<td>{{ item.id }}</td>
<td>{{ item.name }}</td>
</tr>
Normally, the data should be contained in the variable MyData, right?
EDIT: Now, I am facing a new issue where my list is not getting sorted. I am using the orderBy Filter from the AngularJS documentation website.