I have a Service
angular.module('AigServices', ['ngResource']).factory('aiguilleurs', function($resource){
var service = $resource('app/data/EpargneATermeRachetableCELI.json', {}, {
query: {method:'GET', params:{}, isArray:true}});
return service; });
In my controller, when I call aiguilleurs.query(), I receive the structure but no data like it said in the doc. I want to have the data has soon has I call the query(). Any idea? I have looked around and didn't find anything. So the controller code follow ($scope.listeAiguilleurs[0] is always undefined):
$scope.listeAiguilleurs = aiguilleurs.query();
var questionEnCours = null;
if ($scope.listeAiguilleurs[0] != null) {
questionEnCours = $scope.listeAiguilleurs[0].questions[$scope.noQuestionEnCours-1];
}
$scope.questionEnCours = questionEnCours;
That is because the query returns a promise. You can read more about that here. You have to pass a callback to the function (check out the Credit Card Resource example here). Try this:
$scope.listeAiguilleurs = aiguilleurs.query(function () {
var questionEnCours = null;
if ($scope.listeAiguilleurs[0] != null) {
questionEnCours = $scope.listeAiguilleurs[0].questions[$scope.noQuestionEnCours-1];
}
$scope.questionEnCours = questionEnCours;
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With