2016-12-13 29 views
2

のように、私はNG6の定型文を使用していたし、それは素晴らしい構造を生成していました:Angular2(CLI):独立した共通のコンポーネントとロジック・コンポーネントの角1.4では

app 
    common 
    components 
    services 


etc... 

今私はtypescriptですとangular2学ぶしようとしています。 Angular CLIを使用しています。

と私はポートの角度1.4からの構造のいくつかをしたい:私は分離することを意味し、例えば、顧客成分など

から、コンポーネントを選択し、私は、このような構造を作成:

enter image description here

コンポーネント - モジュール、顧客はモジュール、リスト - はコンポーネントです。

私のapp.component.htmlではどのようにリストコンポーネントを使用できますか? Like:

<app-customer-list></app-customer-list> 

モジュール&のインポートに問題があります。

私は、このような方法でそれを実行します。

**app.module.ts** 

import { BrowserModule } from '@angular/platform-browser'; 
import { NgModule } from '@angular/core'; 
import { FormsModule } from '@angular/forms'; 
import { HttpModule } from '@angular/http'; 

import { AppComponent } from './app.component'; 

import { ComponentsModule } from './components/components.module'; 

@NgModule({ 
    declarations: [ 
    AppComponent 
    ], 
    imports: [ 
    BrowserModule, 
    FormsModule, 
    HttpModule, 
    ComponentsModule 
    ], 
    providers: [], 
    bootstrap: [AppComponent] 
}) 
export class AppModule { } 

-

**components.module.ts** 

import { NgModule } from '@angular/core'; 

import { CustomerModule } from './customer/customer.module'; 


@NgModule({ 
    imports: [ 
    CustomerModule 
    ], 
    declarations: [] 
}) 
export class ComponentsModule { } 

-

**customer.module.ts** 

import { NgModule } from '@angular/core'; 
import { CommonModule } from '@angular/common'; 
import { CustomerComponent } from './customer.component'; 
import { ListComponent } from './list/list.component'; 

@NgModule({ 
    imports: [ 
    CommonModule 
    ] 
    declarations: [CustomerComponent, ListComponent] 
}) 
export class CustomerModule { } 

-

**list.component.ts** 

import { Component, OnInit } from '@angular/core'; 

@Component({ 
    selector: 'app-customer-list', 
    templateUrl: './list.component.html', 
    styleUrls: ['./list.component.css'] 
}) 
export class ListComponent implements OnInit { 

    constructor() { } 

    ngOnInit() { 
    } 

} 

どうしたの?どのように正しくインポートできますか?

答えて

2

あなたが他のモジュールと共有しているこれらのモジュールには、コンポーネント/モジュールをエクスポートするために忘れている:

**customer.module.ts** 
 

 
import { NgModule } from '@angular/core'; 
 
import { CommonModule } from '@angular/common'; 
 
import { CustomerComponent } from './customer.component'; 
 
import { ListComponent } from './list/list.component'; 
 

 
@NgModule({ 
 
    imports: [ 
 
    CommonModule 
 
    ] 
 
    declarations: [CustomerComponent, ListComponent], 
 
    exports: [CustomerComponent, ListComponent] 
 
}) 
 
export class CustomerModule { }

**components.module.ts** 
 

 
import { NgModule } from '@angular/core'; 
 

 
import { CustomerModule } from './customer/customer.module'; 
 

 

 
@NgModule({ 
 
    imports: [ 
 
    CustomerModule 
 
    ], 
 
    exports: [CustomerModule] 
 
    declarations: [] 
 
})

+0

笑、右のあなたがいます)ちょうど巨大なタイプミス) – brabertaser19

+0

私は同じことをやったことを心配しないでください!簡単な間違いです... – brando

+0

angular.ioサイトのモジュールについてのこのFAQは役に立ちましたか?https://angular.io/docs/ts/latest/cookbook/ngmodule-faq.html – brando

関連する問題