When using the following code snippet, $scope and $mdDialog are required to be static.
declare var module: any;
export interface IChangePassword extends ng.IScope {
cancel: Function;
myname: string;
state: string;
processRequest: Function;
CurrentPassword: string;
NewPassword: string;
ConfirmPassword: string;
}
export class ChangePasswordController {
static $inject = ["$scope", "$mdDialog","$timeout"];
static $mdDialog: any;
static $timeout: any;
state: string = 'getInput';
static $scope: IChangePassword;
CurrentPassword: string;
NewPassword: string;
ConfirmPassword: string;
ChangePasswordService: any;
constructor($scope: IChangePassword, $mdDialog: any, $timeout: any) {
ChangePasswordController.$mdDialog = $mdDialog;
ChangePasswordController.$scope = $scope;
$scope.state = this.state;
$scope.cancel = this.cancel;
$scope.processRequest = this.processRequest;
//this.ChangePasswordService = ChangePasswordService;
ChangePasswordController.$timeout = $timeout;
}
public cancel ():void {
ChangePasswordController.$mdDialog.cancel();
};
public processRequest(): void {
ChangePasswordController.$scope.state = 'processRequest';
ChangePasswordController.$timeout(function () {
ChangePasswordController.$scope.state = 'Done';
}, 5000);
}
}
module.exports = function (app) {
app.controller("ChangePasswordController", ChangePasswordController);
}
The following code does not work as expected. The reference to this.$scope is always null within processRequest(). Assistance needed.
export class ChangePasswordController {
static $inject = ["$scope", "$mdDialog","$timeout"];
static $mdDialog: any;
static $timeout: any;
state: string = 'getInput';
$scope: IChangePassword;
CurrentPassword: string;
NewPassword: string;
ConfirmPassword: string;
ChangePasswordService: any;
//myname: string = 'gaurav';
constructor($scope: IChangePassword, $mdDialog: any, $timeout: any) {
ChangePasswordController.$mdDialog = $mdDialog;
this.$scope = $scope;
$scope.state = this.state;
$scope.cancel = this.cancel;
$scope.processRequest = this.processRequest;
//this.ChangePasswordService = ChangePasswordService;
ChangePasswordController.$timeout = $timeout;
}
public cancel ():void {
ChangePasswordController.$mdDialog.cancel();
};
public processRequest(): void {
this.$scope.state = 'processRequest';
ChangePasswordController.$timeout(function () {
this.state = 'Done';
}, 5000);
}
}
module.exports = function (app) {
app.controller("ChangePasswordController", ChangePasswordController);
}
An issue arises where $scope is not accessible as an instance variable in the provided code. Suggestions for improvement would be greatly appreciated.
Thank you.