我有兩個組件這樣的:角2 - 獲取組件實例
@Component({
selector: 'comp1',
template: `<h1>{{ custom_text }}</h2>`
})
export class Comp1 {
custom_text:string;
constructor(text:string) {
this.custom_text = text;
}
}
/*********************************************/
@Component({
selector: 'comp2',
directives: [Comp1],
template: `
<b>Comp 2</b>
<comp1></comp1>
`
})
export class Comp2 {
constructor() {
// ...
// How to send my own text to comp1 from comp2
// ...
}
}
是否有可能從COMP1送我自己的文字COMP2?
是否有可能從comp2獲取comp1實例?
謝謝。
看看這個http://blog.mgechev.com/2016/01/23/angular2-viewchildren-contentchildren-difference-viewproviders – TGH