2017-06-27 13 views
1

子コンポーネントを表示しようとしていますが、出力が空白の画面です。タイトルは表示されません。私は角度をつけて新しく助けてください。子要素がアンギュラ4で機能していません

app.component.ts

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

@Component({ 
    selector: 'app-root', 
    templateUrl: './app.component.html', 
    styleUrls: ['./app.component.css'] 
}) 
export class AppComponent { 
    title = 'app'; 
} 

チャイルドコンポーネント

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

@Component({ 
    selector: 'app-test', 
    template: '<h1>Haa</h1>', 

}) 
export class CAppComponent { 

} 

app.module.ts

import { BrowserModule } from '@angular/platform-browser'; 
import { NgModule } from '@angular/core'; 

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

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

app.component.html

<!--The whole content below can be removed with the new code.--> 
<div style="text-align:center"> 
    <h1> 
    Welcome to {{title}}!! 
    </h1> 
    <app-test></app-test> 
</div> 

答えて

3

あなたはdeclarationsであなたのコンポーネントを登録する必要があります。

@NgModule({ 
    declarations: [ 
    AppComponent, CAppComponent <-------------- 
    ], 
    imports: [ 
    BrowserModule, 

ない輸入。

インポートは、コンポーネントをエクスポートする他のモジュール(CommonModuleなど)をインポートするために使用されます。

関連する問題