Suppose we have the following resource (using the ngResource module) which returns an array of JSON results:
app.factory('myApi', function($resource) {
return $resource('/myApi/:param')
// returns an array of json objects
});
And the following main controller:
app.controller('mainController', function(myApi) {
var results = []
var _init = function() {
myApi.get({param: 1234}, function(data) {
results = data.results
});
}
_init();
return {
results: results
}
});
I'd like to run an ng-repeat on the results.
<body ng-controller="mainController as main">
<p ng-repeat="r in main.results">{{r.myResult}}</p>
</body>
I've confirmed that the resource is returning the correct results. However, using the above template, nothing appears.
I'm trying to accomplish this without using $scope and using the "Controller as" syntax. I'm also trying to keep my code clean and maintainable by not using tons of "this.___" in my controller objects (hence returning an object at the end of the controller definition).
What's the cleanest way to solve this problem? I've seen tons of solutions that use $scope, but I don't want to go back to using that object.