這篇文章主要介紹了angular2模組和共享模組詳解,現在分享給大家,也給大家做個參考。
建立模組,用到了共享模組PostSharedModule,共享模組裡麵包含了2個公用的模組:文章管理模組和評論管理模組
1,建立一個模組testmodule.module.ts
import { 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.建立模組路由testmodule.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.執行ng g c test-main,建立元件test-main,修改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>
建立共用模組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 { }
上面是我整理給大家的,希望今後會對大家有幫助。
相關文章:
######################## #
以上是angular2模組和共享模組詳解的詳細內容。更多資訊請關注PHP中文網其他相關文章!