我是 typescript 的新手,我正在尝试使用 UI Router 的 $state
在我的 typescript Controller 中导航。不幸的是,我仍然收到无法解决的 state is not defined
错误。
这是我的 Controller :
module MyApp {
export class LoginController {
email: string;
password: string;
loginForm: any;
state: any;
constructor($state: ng.ui.IStateProvider) {
this.state = $state;
};
login() {
if (this.loginForm.$invalid) {
return;
}
console.log(`Login was clicked, email is ${this.email} and password is ${this.password}`);
state.go('Dashboard');
}
}
}
angular.module('myApp').controller('loginController', MyApp.LoginController);
如有任何帮助,我们将不胜感激。
最佳答案
您在 Controller 构造时将 $state
分配给 this.state
。
这意味着它应该在整个对象中被称为 this.state
。
关于javascript - Angular typescript Controller 中的“状态未定义”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35437882/