我想使用通過ng-content
傳遞給下列組件的文本。使用@ContentChild查詢ng-Container的文本
@Component({
selector: 'child-component',
template: '<ng-content></ng-content>'
})
export class ChildComponent implements AfterContentInit {
@ContentChild('value') text: ElementRef;
ngAfterContentInit(): void {
// This does not work
let value = this.text.nativeElement.nextSibling.textContent as string;
}
}
父組件包括這樣的:
<child-component>
<ng-container #value>My Content</ng-container>
</child-component>
我怎樣才能從ContentChild字符串 「我的內容」?
它不工作嗎? https://plnkr.co/edit/nkqXNNzBVkZ79PzG8u2u?p=preview – yurzui