javascript - Uncaught TypeError: Cannot read property 'sheet' of null -


i'm learning angularjs, , run in problem after changing 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 receive 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 called here:

$scope.sessions = sessions.glist(); 

then

ng-repeat="session in sessions" 

while don't use sheet in code. help?

the problem here during time in http request got response,the ng-repeat sessions in script called. means value of sessions null , think try access {{ session.sheet }} in html undefined , browser telling you. solution such problem use $q.defer.resolve() , $q.defer.reject() http response , error. pass through $q.promise. example 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 access

httpservice().then(function(res){  $scope.sessions = res; }); 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -