i have this javascript code:
myApp.factory('Reddit', function($http) {
var Reddit = function() {
this.items = [];
this.busy = false;
this.after = '';
};
Reddit.prototype.nextPage = function() {
console.log(this.items);// []
$http({method: 'GET', url: url}).
success(function(data, status, headers, config) {
console.log(this.items); // undefined ?? how to access to items list
})
How can access to items list in success function?
thisin success callback refers to the callback function, notRedditobject, thereforethis.itemsis undefined. See @ogc-nick's answer on how to avoid this.