Angular 我是否可以将ng模板用于单独的组件,并在其他html中使用其模板引用?
我正在尝试使用ng模板作为一个单独的html组件,并尝试在其他html中使用它的引用。。可能吗?如果是这样的话,我尝试了以下方法,并想了解我的错误是什么 ng-template.htmlAngular 我是否可以将ng模板用于单独的组件,并在其他html中使用其模板引用?,angular,typescript,angular8,angular-directive,Angular,Typescript,Angular8,Angular Directive,我正在尝试使用ng模板作为一个单独的html组件,并尝试在其他html中使用它的引用。。可能吗?如果是这样的话,我尝试了以下方法,并想了解我的错误是什么 ng-template.html <ng-template #sample1> <p>ng template content</p> </ng-template> <div *ngIf="found;"> <ng-container *ngTemplateOutle
<ng-template #sample1>
<p>ng template content</p>
</ng-template>
<div *ngIf="found;">
<ng-container *ngTemplateOutlet="sample1"></ng-container>
</div>
我认为如果您想在应用程序中全局使用规则的角度组件,那么应该使用规则的角度组件,而不是
ng模板
我不知道你为什么要这样做。无论如何,这个链接可能会帮助你
export class DisplayTemplateComponent {
@ViewChild('sample1', {static: false}) sample1: ElementRef;
found = true;
}