I am using ES6 classes to create an angular controller. I am trying to use promises to load my products. When I call getProducts the results comes back with the data I need, however the this in this.products = results is undefined and I get "Cannot set property 'products' of undefined". How can I access the properties from inside of then?
export class ProductController {
constructor (Product) {
'ngInject';
this.ProductService = Product;
this.products = [];
this.getProducts();
}
getProducts() {
this.ProductService
.find()
.$promise
.then(function (results) {
this.products = results;
}, function (results) {
console.log(results);
});
}
}