javascript - Angular typescript Controller 中的“状态未定义”

标签 javascript angularjs controller typescript angular-ui-router

我是 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/

相关文章:

javascript - 为什么setTimeout执行timeExpired没有延迟?

javascript - 如何更改 dxDataGrid 上的文本 "Select all"?

javascript - AngularJs - 如何在导航到新路线时清理 Controller

ios - 从图像选择器返回时如何更改 View Controller ?

javascript - IE 11 中的 PDF 查看器与顶部下拉滚动条重叠

javascript - 在创建 Web 组件时设置其属性

javascript - Json解码 “Trying to get property of non-object”错误

javascript - 将 Controller 动态添加到 app.js Controller 中 : [] - Ext-JS 4

c# - 来自另一个类库的基本 Controller 在 web api 中不起作用

javascript - 如何在jsp中动态显示 '✔'