1
私は、角でdom操作を学ぶために凝視しており、templateRefとそのメソッドcreateEmbeddedViewについて気づいています。この方法についてもっと知りたいと思っています。angle4のTemplateRefのcreateEmbeddedViewメソッドの使い方は?
@Component({
selector: 'app-root',
template: `
<ng-template #template let-name='fromContext'><div>{{name}}</ng-template>
<ng-container #vc></ng-container>
`
})
export class AppComponent implements AfterViewChecked {
@ViewChild('template', { read: TemplateRef }) _template: TemplateRef<any>;
@ViewChild('vc', {read: ViewContainerRef}) vc: ViewContainerRef;
constructor() { }
ngAfterViewChecked() {
const view = this._template.createEmbeddedView({fromContext: 'John'});
this.vc.insert(view);
}
}
それともできます。今、すべての私の質問は、あなたが、その後ViewContainerRef
経由でDOMにそのビューを添付createEmbeddedView
方法を使用して埋め込まれたビューを作成することができます
@Component({
selector: 'app-root',
template: `
<ng-template #template>
</ng-template>
`
})
export class AppComponent implements AfterViewChecked {
@ViewChild('template', { read: TemplateRef }) _template: TemplateRef<any>;
constructor() { }
ngAfterViewChecked() {
this._template.createEmbeddedView('this is a embedded view')
}
}
コンテキストタイプは何ですか、文字列ですか? vcとは何ですか?viewContainerRefですか? –
@ LijinDurairaj、私は答えを –
はい、私は理解したが、私の質問は、あなたのコードでも言及した "コンテキスト"タイプは何ですか。 は、値ieをとる文字列です。