物业' $ routeConfig'类型不存在'($ router:any)=>空隙'

时间:2015-08-26 12:22:02

标签: javascript angularjs typescript angular-new-router

我正在尝试在v1.4中使用角度新路由器。我正在使用Typescript。当我尝试编译时,我收到以下错误。

Property '$routeConfig' does not exist on type '($router: any) => void'

这是我的代码

 /// <reference path="../Scripts/typings/angularjs/angular.d.ts"/>
/// <reference path="../Scripts/typings/angularjs/angular-route.d.ts"/>
module Application {
    "use strict";
    angular.module("app", ['ngNewRouter']);
    export var getModule: () => ng.IModule = () => {
        return angular.module("app");
    }

    getModule().controller('AppController', ['$router', AppController]);

    AppController.$routeConfig = [{
        path: '/',
        component: 'home'
    }, {
            path: '/detail/:id',
            component: 'detail'
        }, {
            path: '/login',
            component: 'login'
        }];

    function AppController($router) {

    }

}

感谢任何帮助。感谢。

2 个答案:

答案 0 :(得分:1)

您可以选择使用模块或类。

模块路线:

module AppController {
    export let $routeConfig = [{
        path: '/',
        component: 'home'
    }, {
        path: '/detail/:id',
        component: 'detail'
    }, {
        path: '/login',
        component: 'login'
    }];
}

function AppController($router) {

}

和班级路线:

class AppController {
    static $routeConfig = [{
        path: '/',
        component: 'home'
    }, {
        path: '/detail/:id',
        component: 'detail'
    }, {
        path: '/login',
        component: 'login'
    }];

    constructor($router) {

    }
}

根据您的需要,使用最适合您的方式。

答案 1 :(得分:0)

我以某种方式使它工作。以下是代码。现在新路由编译并正常运行。

/// <reference path="../Scripts/typings/angularjs/angular.d.ts"/>
/// <reference path="../Scripts/typings/angularjs/angular-route.d.ts"/>
module Application {
    "use strict";
    angular.module("app", ['ngNewRouter']);
    export var getModule: () => ng.IModule = () => {
        return angular.module("app");
    }

    var AppController: any, $routeConfig: any;

    getModule().controller('AppController', ['$router', AppController = ($router) => {    }]);

    AppController.$routeConfig = [
        {
            path: '/',
            component: 'home'
        },
        {
            path: '/detail/:id',
            component: 'detail'
        },
        {
            path: '/login',
            component: 'login'
        }];
}