我正在尝试使用v1.4中的angular新路由器。我正在使用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) {
}
}
任何帮助都是感激的。谢谢。
您有两个选择,要么使用模块,要么使用类。
模块路由:
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) {
}
}
根据您的需要,使用最适合您的
我设法使它工作。下面是代码。现在新的路由编译好了,没有任何错误。
/// <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'
}];
}