Why is it that I can't access $scope outside of the constructor, unless I use the fat arrow function? Is there a way to access $scope without using the fat arrow function?
namespace FooBar {
export interface MyScope extends ng.IScope {
message: string;
}
export class SandboxCtrl {
static $inject = ["$scope", "$timeout"];
private scope: MyScope;
private timeout: ITimeoutService;
constructor($scope: MyScope, $timeout: ng.ITimeoutService) {
this.scope = $scope;
this.timeout = $timeout;
timeout(this.foo, 1000); // does not work
timeout(this.bar, 1000); // works
}
public foo() {
this.scope.message = "foo bar"; // does not work
}
bar = () => {
this.scope.message = "foo bar"; // works
}
}
}
UPDATE Upon further investigation, I discovered that the issue was caused by the $timeout directive. I have updated my example accordingly.