ASP Core Angular SPA模板module.ts配置

时间:2017-06-20 18:34:30

标签: asp.net-mvc angular

ASP Core SPA模板中有3个不同的app.module文件

  1. app.module.client.ts
  2. app.module.server.ts
  3. app.module.shared.ts
  4. 我在app.module.shared.ts提供程序中包含了我的服务,但它仍然没有显示在运行时定义的提供程序。通常我们有一个角度的app.module.ts文件,当我在那里定义我的服务时它工作得很好。任何帮助都将受到高度赞赏。

    app.module.share.ts

    export const sharedConfig: NgModule = {
    bootstrap: [ AppComponent ],
    declarations: [
        AppComponent,
        DashboardComponent,
        NavComponent,
        SidebarComponent,
        PluginComponent,
        HomeComponent,
        DashboardUIComponent,
        SchoolInfoComponent,
        HomeMainComponent,
        StudentInfoComponent,
        NavMainComponent,
        LoginComponent,
        RegisterComponent,
        ClassInfoComponent,
        ClassComponent
    ],
    imports: [
        BrowserModule,
        RouterModule.forRoot(APP_ROUTES),
    ],
    providers: [MenuService, VariablesService, navPillsService] };
    

    app.module.client.ts

    @NgModule({
    bootstrap: sharedConfig.bootstrap,
    declarations: sharedConfig.declarations,
    imports: [
        BrowserModule,
        FormsModule,
        HttpModule,
        ...sharedConfig.imports
    ],
    providers: [
        { provide: 'ORIGIN_URL', useValue: location.origin, ...sharedConfig.providers }
    ] }) export class AppModule { } 
    

    app.module.server.ts

    @NgModule({
    bootstrap: sharedConfig.bootstrap,
    declarations: sharedConfig.declarations,
    imports: [
        ServerModule,
        ...sharedConfig.imports
    ],
    providers: sharedConfig.providers  }) export class AppModule { }
    

    错误:

    enter image description here

1 个答案:

答案 0 :(得分:0)

我认为这段代码可能不正确:

providers: [
    { provide: 'ORIGIN_URL', useValue: location.origin, ...sharedConfig.providers }
] }) export class AppModule { } 

我认为sharedConfig片段必须在括号之外?

providers: [
    { provide: 'ORIGIN_URL', useValue: location.origin}, 
     ...sharedConfig.providers
] }) export class AppModule { }