這次帶給大家,的注意事項有哪些,下面就是實戰案例,一起來看一下。
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 { }
相信看了本文案例你已經掌握了方法,更多精彩請關注php中文網其它相關文章!
推薦閱讀:
以上是使用angular2模組和共享模組的詳細介紹的詳細內容。更多資訊請關注PHP中文網其他相關文章!