Encountering a similar issue to the one discussed here: AngularJS directive binding a function with multiple arguments
Following the guidance provided in this answer:
Condensing the information as much as possible.
Here is the working example:
<my-directive on-save="ctrl.saveFn"></my-directive>
Implemented as:
angular.module('app')
.controller('MyController', function($scope) {
var vm = this;
vm.saveFn = function(value) { vm.doSomethingWithValue(value); }
});
However, upon converting to Typescript and utilizing real classes, the functionality breaks.
class MyController {
constructor() {}
saveFn(value) {
this.doSomethingWithValue(value);
}
}
When debugging the Typescript version, it is observed that "this" is referencing the Window global object. This causes issues with the scope, but the solution to this problem remains elusive. How can I ensure that "this" refers to the MyController class as intended?