The callback you pass to the promise gets called asynchronously. In that case, this
refers to the default context, which is the global window
in the browser, and module
in node.js, for example.
If you want to prevent this, use .bind()
to set the context of the function to your liking. (Note: Without polyfill, .bind()
is not available until IE9)
this.initialize = function () {
settings.listFn().then(function (response) {
angular.copy(response, items);
if (response.length > 0) {
that.setCurrentItem(response[0]);
}
}.bind(this));
}