2017-06-20 103 views
0

有在ASP核心SPA模板3個不同app.module文件ASP核心角SPA模板module.ts配置

  1. app.module.client.ts
  2. app.module.server.ts
  3. app.module.shared.ts

我已將我的服務包含在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

回答

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 { } 
+0

謝謝,它現在的工作:) –