您好,登錄后才能下訂單哦!
這篇文章主要介紹angular2模塊和共享模塊的示例分析,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!
創建模塊,用到了共享模塊PostSharedModule,共享模塊里面包含了2個公用的模塊:文章管理模塊和評論管理模塊
1,創建一個模塊testmodule.module.ts
import { CommonModule } from '@angular/common'; import { NgModule } from '@angular/core'; import { RouterModule } from "@angular/router"; import { <span ><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 >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模塊和共享模塊的示例分析”這篇文章的所有內容,感謝各位的閱讀!希望分享的內容對大家有幫助,更多相關知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。