答案得到基類實例:角2 - 不能與ViewChild也不ContentChild
不使用EXPORTAS
使用@ViewChild( '爲myContent')爲myContent;獲取父類
如果視圖被初始化它只會工作的實例,所以最好使用ngAfterViewInit
這涉及繼承!
base class (component)
|
inherited class (component)
我有EXPORTAS導出的基類組分
@Component({
selector: 'my-content',
exportAs: 'myContent',
...
})
繼承的類組分在繼承的使用其自己的模板
<my-content #myContent>
...
基類模板 一個參考組件的代碼我嘗試獲取其實例
@ViewChild('myContent') myContent;
或
@ContentChild('myContent') myContent;
有人說這應該工作,但爲myContent常是不確定的
我該如何解決這個問題?
感謝
你能在Plunker重現? –