I'm learning AngularJS, and run in to a problem after changing this function:
gList : function (){
return List
},
With this:
gList : function() {
$http({method:'GET',url:'/sessions'}).
success(function(data){
return data;
}).
error(function(data){
$log.info(data);
})},
And now I receive this error:
Uncaught TypeError: Cannot read property 'sheet' of null
(anonymous function) modernizr-2.6.2.min.js:4
y modernizr-2.6.2.min.js:4
s.fontface modernizr-2.6.2.min.js:4
(anonymous function) modernizr-2.6.2.min.js:4
(anonymous function) modernizr-2.6.2.min.js:4
The function is called here:
$scope.sessions = Sessions.gList();
Then
ng-repeat="session in sessions"
While I don't even use sheet
in my code. Help?
The problem here is during the time in which your http request got response,the ng-repeat sessions in script already called. It means that the value of sessions is null and i think you try to access {{ session.sheet }} in your HTML which is undefined and so browser telling you. The solution for such problem is use $q.defer.resolve() and $q.defer.reject() for http response and error. Than pass the through $q.promise. An example is given below :
.service('httpService' , ['$http','$q', function($http, $q) ]{
$http(sendConfig).then(function(response) {
deferred.resolve(response);
}, function(response) {
deferred.error(response);
}, function(message) {
deferred.notify(message);
});
return deferred.promise;
});
And in controller try to access this
httpService().then(function(res){
$scope.sessions = res;
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.