gpt4 book ai didi

javascript - 类型 '$routeConfig' 上不存在属性 '($router: any) => void'

转载 作者:行者123 更新时间:2023-11-27 23:56:29 25 4
gpt4 key购买 nike

我正在尝试使用 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)路线:

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

constructor($router) {

}
}

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

关于javascript - 类型 '$routeConfig' 上不存在属性 '($router: any) => void',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32226557/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com