如何将组件的投影含量移动到投影后的不同位置,例如在角度材料中

问题描述 投票:0回答:1
angular typescript angular-material
1个回答
0
投票
parent component中的usage

import { AfterViewInit, Component, ContentChild, TemplateRef, ViewContainerRef } from '@angular/core'; @Component({ selector: 'my-projection', template: `<ng-template #contentTemplate><ng-content></ng-content></ng-template>`, }) export class MyProjectionComponent implements AfterViewInit { @ContentChild('contentTemplate', { static: true }) contentTemplate!: TemplateRef<any>; constructor(private viewContainerRef: ViewContainerRef) {} ngAfterViewInit() { // Move projected content to parent container this.viewContainerRef.createEmbeddedView(this.contentTemplate); } }

	

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.