2016-11-19 15 views
1

メインコンポーネントのテンプレート内のセレクタを使用して、メインコンポーネント内の子コンポーネント、app.componentを使用しようとしています。しかし、それは動作していません。私はChildComponentAngular2の親コンポーネントで子コンポーネントを使用できません

app.module.tsについては、以下のようにモジュール内の宣言を行った

child.component.ts

import { Component} from '@angular/core'; 
@Component({ 
selector: 'child-component', 
templateUrl: `<p>Child Component</p>` 
}) 
export class ChildComponent { } 

app.component.ts

import { Component } from '@angular/core'; 
import { ChildComponent} from './child.component'; 

@Component({ 
selector: 'my-app', 
template: `<h1>Hello Angular!</h1> 
<child-component> </child-component>  ` 
}) 

export class AppComponent { } 

import { NgModule } from '@angular/core'; 
import { BrowserModule } from '@angular/platform-browser'; 
import { ChildComponent} from './child.component'; 
import { AppComponent } from './app.component'; 

@NgModule({ 
imports: [BrowserModule], 
declarations: [AppComponent,ChildComponent], 
bootstrap: [AppComponent] 
}) 

export class AppModule { } 

How to import component into another root component in Angular 2に記載されている解決策は機能しません。

解像度でお手伝いください。

答えて

1

child-componentのメタオプションが入っています。

templateUrl: `<p>Child Component</p>` 

は、このために

template: `<p>Child Component</p>` 
+0

おかげで多くのことをする必要があります。マジックのように今働いています。どのように私はそれをデバッグするか教えてください。私は端末/コンソールからそれをトレースするのに成功しませんでした。 –

+0

ブラウザコンソール内のエラーメッセージは説明的なものです。最初に見てください –

関連する問題