Home > Article > Web Front-end > How to use angular2 modules with shared modules
This time I will show you how to use angular2 modules and shared modules, and what are the precautions for using angular2 modules and shared modules. The following is a practical case, let's take a look.
To create the module, the shared module PostSharedModule is used. The shared module contains two common modules: article management module and comment management module1, create a module testmodule.module.tsimport { CommonModule } from '@angular/common'; import { NgModule } from '@angular/core'; import { RouterModule } from "@angular/router"; import { <span style="color:#cc0000;"><strong>PostSharedModule </strong></span>} from '../shared/post.module'; import { testModule } from './testmodule.routes'; import { TestMainComponent } from './test-main/test-main.component'; import { PostTableService } from '../manage/post-table/services/post-table.service'; @NgModule({ declarations: [ TestMainComponent ], imports: [ CommonModule, <span style="color:#ff0000;">PostSharedModule</span>, RouterModule.forChild(testModule) ], exports:[ TestMainComponent ], providers: [ PostTableService ] }) export class TestModule { }2. Create module
routestestmodule.routes.ts
import { TestMainComponent } from './test-main/test-main.component'; import { PostTableComponent } from '../manage/post-table/post-table.component'; import { CommentTableComponent } from '../manage/comment-table/comment-table.component'; export const testModule = [ { path:'', component:TestMainComponent, children: [ { path: '',redirectTo:'posttable/page/1',pathMatch:'full'}, { path: 'posttable/page/:page', component: PostTableComponent }, { path: 'commenttable/page/:page', component: CommentTableComponent }, { path: '**', redirectTo:'posttable/page/1' } ] } ];3. Execute ng g c test-main, create component test-main, modify test-main.component .html
<a routerLink="posttable/page/1" class="list-group-item"><span class="badge">10000</span>文章管理</a> <a routerLink="commenttable/page/1" class="list-group-item"><span class="badge">1000000</span>评论管理</a>Create shared module post.module.ts
import { NgModule } from '@angular/core'; import { ModalModule } from 'ng2-bootstrap'; import { PaginationModule } from 'ng2-bootstrap'; import { SharedModule } from './shared.module'; import { CommentTableComponent } from '../manage/comment-table/comment-table.component'; import { PostTableComponent } from '../manage/post-table/post-table.component'; @NgModule({ imports:[ SharedModule, ModalModule.forRoot(), PaginationModule.forRoot() ], declarations:[ CommentTableComponent, PostTableComponent ], exports:[ ModalModule, PaginationModule, CommentTableComponent, PostTableComponent ] }) export class PostSharedModule { }I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the PHP Chinese website! Recommended reading:
How to use vue2.0 resource file assets and static
Use React Router v4 from scratch
The above is the detailed content of How to use angular2 modules with shared modules. For more information, please follow other related articles on the PHP Chinese website!