angular2模塊和共享模塊詳解
創(chuàng)建模塊,用到了共享模塊PostSharedModule,共享模塊里面包含了2個(gè)公用的模塊:文章管理模塊和評(píng)論管理模塊
1,創(chuàng)建一個(gè)模塊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.創(chuàng)建模塊路由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.執(zhí)行ng g c test-main,創(chuàng)建組件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>評(píng)論管理</a>
創(chuàng)建 共享模塊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 {
}
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
將angular-ui的分頁(yè)組件封裝成指令的方法詳解
這篇文章主要給大家介紹了將angular-ui的分頁(yè)組件封裝成指令的方法,文中介紹的非常詳細(xì),相信會(huì)對(duì)大家的學(xué)習(xí)或者工作覺有一定的參考價(jià)值,需要的朋友下面來(lái)一起看看吧。2017-05-05
AngularJS控制器controller正確的通信的方法
AngularJS中的controller是個(gè)函數(shù),用來(lái)向視圖的作用域($scope)添加額外的功能,我們用它來(lái)給作用域?qū)ο笤O(shè)置初始狀態(tài),并添加自定義行為2016-01-01

