I have a Typescript directive class and a controller class like below. I want to set a watch on isolated scope variable in the Typescript controller class. I am not able to access the isolated scope variables inside the controller class.
How can I do that?
My directive class:
module Sgm.Workspace.Web.Users {
"use strict";
export class UwAuthority implements ng.IDirective {
restrict = "E";
replace = false;
templateUrl = "/app/features/users/uwAuthority.html";
scope = {
showParameters: '=showParameters'
};
controller = UwAuthorityController;
//controllerAs = "vm";
link(scope: ng.IScope, element: ng.IAugmentedJQuery, attr: ng.IAttributes, controller: UserParametersController): void {
}
static instance(): ng.IDirective {
return new UwAuthority();
}
}
angular.module("workspaceApp")
.directive("showUwAuthority", UwAuthority.instance)
.controller("UwAuthorityController", ['userService', '$scope', (userService: Sgm.Workspace.Web.Services.IUserService, $scope: ng.IScope) => new UwAuthorityController(userService, $scope)]);
}
and my controller class is
module Sgm.Workspace.Web.Users {
export interface IUwAuthorityController {
loadFinancingType(): void;
}
export class UwAuthorityController implements IUwAuthorityController {
public modernBrowsers: any = [];
public outputBrowsers: any = [];
public localLang: any = [];
public showParameters: boolean;
static $inject = ['userService', '$scope'];
constructor(
private userService: Services.IUserService,
private $scope: ng.IScope) {
var vm = this;
var a = this.showParameters;
this.loadFinancingType();
this.$scope.$watch(() => this.showParameters, (oldValue: string, newValue: string) => {
console.log("showParameters")
});
this.$scope.$watch(() => this.outputBrowsers, (oldValue: string, newValue: string) => {
this.tellmeItChanged(oldValue, newValue);
});
}
public loadFinancingType = (): void => {
this.modernBrowsers = [{
name: "JUMBO 5/1 LIBOR ARM EVERBANK",
ticked: false
}];
this.localLang = {
selectAll: "All",
selectNone: "None",
reset: "Reset",
search: "Search...",
nothingSelected: "Select"
}
}
private tellmeItChanged(oldValue: string, newValue: string) {
if (oldValue !== newValue) {
if (this.outputBrowsers.length > 1) {
document.getElementById('plan').childNodes[0].childNodes[0].nodeValue = this.outputBrowsers.length + ' Selected';
}
}
}
}
}
this.$scope.$watch(() => $scope.showParametersorthis.$scope.$watch('showParameters'.