angular2模塊和共享模塊詳解
創(chuàng)建模塊,用到了共享模塊PostSharedModule,共享模塊里面包含了2個公用的模塊:文章管理模塊和評論管理模塊
1,創(chuàng)建一個模塊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>評論管理</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 {
}
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
實例剖析AngularJS框架中數(shù)據(jù)的雙向綁定運用
這篇文章主要介紹了AngularJS框架中數(shù)據(jù)的雙向綁定運用實例,包括數(shù)據(jù)綁定中的關(guān)鍵函數(shù)與監(jiān)聽器觸發(fā)的相關(guān)講解,需要的朋友可以參考下2016-03-03
angularjs 的數(shù)據(jù)綁定實現(xiàn)原理
本篇文章主要介紹了angularjs 的數(shù)據(jù)綁定實現(xiàn)原理,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-07-07
AngularJS基礎(chǔ) ng-non-bindable 指令詳細(xì)介紹
本文主要講解AngularJS ng-non-bindable 指令,這里幫大家整理了ng-non-bindable指令的基本知識資料,有需要的小伙伴可以參考下2016-08-08
AngularJS中取消對HTML片段轉(zhuǎn)義的方法例子
這篇文章主要介紹了AngularJS中取消對HTML片段轉(zhuǎn)義的方法例子,在一些需要顯示HTML的地方,就要取消AngularJS的轉(zhuǎn)義,本文就介紹了這種方法,需要的朋友可以參考下2015-01-01
angularJS的radio實現(xiàn)單項二選一的使用方法
下面小編就為大家分享一篇angularJS的radio實現(xiàn)單項二選一的使用方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-02-02
詳解創(chuàng)建自定義的Angular Schematics
本文對 Angular Schematics 進(jìn)行了介紹,并創(chuàng)建了一個用于創(chuàng)建自定義 Component 的 Schematics ,然后在 Angular 項目中以它為模板演練了通過 Schematics 添加自定義的 Component,感興趣的小伙伴們可以參考一下2018-06-06
Angular應(yīng)用打包和部署實現(xiàn)過程詳解
這篇文章主要為大家介紹了Angular應(yīng)用打包和部署實現(xiàn)過程詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-08-08

