に宣言せず、私は、2つの成分Angular2 [2.4.10]インポート子コンポーネントAppModule
parent.component.ts
@Component({
selector: 'my-element',
template: ` <h4>{{title}}</h4>
<child-element></child-element> //<-- Here I want to take data from child element
`
})
export class ParentComponent {
title = 'This is parent!';
}
私が試しchild.component.ts
@Component({
selector: 'child-element',
template: `
<h4>{{childTitle}}</h4>
`
})
export class ChildComponent {
childTitle = 'This is Child';
}
を有しますparent.component.tsで次のように追加しましたが、うまくいきませんでした。
@NgModule({
imports: [ChildComponent],
providers: []
})
もう1つの質問 - コンポーネントの数があり、お互いに通信したい場合。それをApp.module.tsにすべてオーバーヘッドで追加するのですか?彼らは起動してロードされます。私がここに間違っていれば私を修正してください。
私は50のようなすべてのコンポーネントを宣言する必要があるapp.moduleが心配です。先に 'directives:[ComponentName]'と一緒に使用できます – Anoop