ホームページ  >  記事  >  ウェブフロントエンド  >  angular2 モジュールを共有モジュールで使用する方法

angular2 モジュールを共有モジュールで使用する方法

php中世界最好的语言
php中世界最好的语言オリジナル
2018-05-26 14:50:091151ブラウズ

今回は、angular2 モジュールと共有モジュールの使用方法と、angular2 モジュールと共有モジュールを使用する際の 注意事項 について説明します。以下は実際的なケースです。

モジュールを作成するには、共有モジュール PostSharedModule を使用します。共有モジュールには、記事管理モジュールとコメント管理モジュールの 2 つの共通モジュールが含まれています

1. モジュール testmodule.module.ts を作成します

rreee

2.

testmodule.routes.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 { }
3. ng g c test-main を実行し、コンポーネント test-main を作成し、test-main.component.html を変更します

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' } 
    ] 
  } 
];

共有モジュール post.module.ts を作成します

<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>

この記事を読んでください。あなたはケースメソッドをマスターしました。さらに興味深い情報については、php 中国語 Web サイトの他の関連記事に注目してください。

推奨書籍:

vue2.0 リソース ファイル アセットと静的リソースの使用方法


React Router v4 を最初から使用する

以上がangular2 モジュールを共有モジュールで使用する方法の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。