I have function like below, and I have problem because of this context. When I run my code, I have error in my console: Cannot set property 'cat' of undefined
When I change this.cat for $scope.cat, everything is fine. I tried add $scope.apply and timeout, but it doesn't works. It seems like this change context, but I dont't know how to repair it.
(function () {
angular.module('test.module')
.component('testComponent', {
bindings: {},
templateUrl: 'js/modules/test/test.html',
controllerAs: 'vm',
controller: (TestService, $scope) => {
TestService.changed(() => {
const testValue = test.findById(id)
if (testValue && testValue.data) {
this.cat = testValue.data
}
})
}
})
})()