Sort of fighting with this at the moment as I don't understand why its happening. I'll show you the controller.
class ExampleClassController {
constructor($scope, serviceItem, PrepService, consts) {
// Services
this.serviceItem = serviceItem;
// Init Values
this.grid = PrepService;
this.dates = [
moment().format('x'),
moment().add(14, 'days').format('x')
];
// Works fine
console.log(this._init());
// Events
$scope.$on(consts.events.change, this._init);
}
_init() {
// this.grid = {};
// Returns null
console.log(this, "in the init");
return this.serviceItem.get().then((res) => this.grid = res);
}
}
Here is the weird part, when I call this._init inside the constructor, its fine. Returns the promise as suggested. But when I call it in the $scope.$on event it just falls apart and says that this is null. I can't seem to figure out why its happening as it doesn't seem to happen to anyone else's example. Anything would be helpful, just insight as to why would be awesome.
Thanks!