我试图在路由模块中创建一个实例,但我总是得到错误"类不是构造函数"
这是我的代码:
export class Modules{
modules : object = {
masterdata : MasterdataModule,
shop : ShopModule
};
public constructor(){
}
public isActive(module : string) : boolean{
return this.getModules().hasOwnProperty(module);
}
public getModules() : object{
return this.modules;
}
public getActiveModules() : any[]{
return ActiveModules();
}
}
这是我的班级路由,我试图从模块中创建一个实例。
import { RouterModule, Routes } from '@angular/router';
import {Modules} from "./modules";
export class Route{
Modules : Modules;
public constructor(){
this.Modules = new Modules;
}
public routes() : Routes{
let routes = [
{ path: '', component: HomeComponent},
{ path: 'about', component: AboutComponent},
{ path: 'apidemo', component: ApiDemoComponent},
{ path: 'tabledemo', component: TableDemoComponent},
{ path: 'dashboarddemo', component: DashboardDemoComponent },
{ path: 'timelinedemo', component: TimelineDemoComponent},
{ path: 'formdemo/:id', component: FormDemoComponent},
{ path: 'infopage/:subject', component: DemoPageComponent}
];
console.log(this.Modules.isActive("Shop"));
return routes;
}
}
这两个类都在单独的文件中
答案 0 :(得分:-1)
问题是您的“模块”变量与您的“模块”类具有相同的名称。变量应始终小写以避免此类冲突。
export class Route{
modules : Modules;
public constructor(){
this.modules = new Modules();
}