I have been trying to resolve a $http
request within the $stateProvider.state
declaration which works well. console.log
returns the JSON data, but I cannot seem to access it from within the controller.
I created a tabs app using ionic cli
Here’s what I got.
$stateProvider
.state('tab.search', {
url: '/search',
resolve: {
estates: ["$http", function($http){
$http.get('/data/Estates.json').then(function(res) {
console.log(res) // shows the array
return res.data;
});
}]
},
views: {
'tab-search': {
templateUrl: 'templates/tab-search.html',
controller: 'FriendsCtrl'
}
}
})
and the controller is simply
.controller('FriendsCtrl', ["$scope", "estates", function($scope, estates) {
alert(JSON.stringify(estates)) // undefined
}]);
What am I doing wrong? The alert(estates)
returns undefined
!
EDIT
I tried putting the resolve
within the views object and it still returns undefined