运行一个有角度的两页项目

时间:2018-08-01 11:30:21

标签: angular angular-ui-router

我是Angular的初学者。我有一个有两页的角度项目。每个页面都有自己的模块。当我运行“ ng serve”时,它将运行app.module.ts。但是我想运行另一个页面,该模块称为“ some-page.module.ts”。我怎样才能做到这一点?

2 个答案:

答案 0 :(得分:1)

在您的main.ts文件中,您将找到

platformBrowserDynamic()。bootstrapModule(AppModule),可在应用程序启动时引导正确的模块。

答案 1 :(得分:0)

通常,AppModule 应该是自举模块。然后,您可以拉入其他模块,如下所示:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { HttpClientModule } from '@angular/common/http';
import { RouterModule } from '@angular/router';

import { AppComponent } from './app.component';
import { WelcomeComponent } from './home/welcome.component';
import { ProductModule } from './products/product.module';

@NgModule({
  declarations: [
    AppComponent,
    WelcomeComponent
  ],
  imports: [
    BrowserModule,
    HttpClientModule,
    RouterModule.forRoot([
      { path: 'welcome', component: WelcomeComponent },
      { path: '', redirectTo: 'welcome', pathMatch: 'full' },
      { path: '**', redirectTo: 'welcome', pathMatch: 'full' }
    ]),
    ProductModule
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }

declarations定义AppModule中的组件。

imports定义了此模块使用的其他模块。请注意此处指定的ProductModule。这是提供所有产品功能页面的模块。

有关完整示例,请查看以下内容:https://github.com/DeborahK/Angular-GettingStarted/tree/master/APM-Final