Can not read property 'push' of undefined

1

I have a problem implementing the ngInfiniteScroll library of angularJs with Laravel, the truth is not given with that error here my Corner Services

function PostServices($http, $q, CONFIG) {
  return {
        getPots: getPots,
      //  postCheck: postCheck,
        postSave: postSave
    };

    this.recipes = [];
    this.loading = false;
    this.page = 1;


   function getPots() {

     var url = CONFIG.APIURL + 'post/ajaxviewpublish?page=' + this.page;
     if (this.loading) return;
     this.loading = true;
     $http.get(url)
     .success(function (data) {
       console.log(data.message.data);
       for (var i = 0; i < data.message.data.length; i++) {
           this.recipes.push(data.message.data[i]);
       }
       this.page++;
       this.loading = false;
       recipes.loading = true; // This should prevent more code from being loaded.
   }.bind(this));


   }
   return getPots;
    
asked by vdjkelly 09.05.2016 в 00:30
source

1 answer

2

Maybe 'this' is referring to the wrong object, try the following:

...

var self=this;
self.recipes=[];
...

$http.get(url)
 .success(function (data) {
   console.log(data.message.data);
   for (var i = 0; i < data.message.data.length; i++) {
       self.recipes.push(data.message.data[i]);
   }

You may have to do the same for page and loading

    
answered by 09.05.2016 / 14:04
source