我正在使用Angular 7,但是在我的HTML中编写以下代码时没有得到响应。
<ng-template *ngIf="isStatus">
... line of code...
</ng-template>
请帮助我,这里我做错了。
答案 0 :(得分:0)
如果您正在使用,请使用如下结构指令 替换代码如下:
<ng-template [ngIf]="condition">
..............
</ng-template>
希望这可以为您提供帮助。有关更多信息,请参见https://angular.io/api/common/NgIf
答案 1 :(得分:0)
<ng-template *ngIf="isStatus()" pTemplate="body">
....line of code
<ng-template>
使用函数并从那里返回true或false。希望它能工作
答案 2 :(得分:0)
您可以这样做:-
<ng-template [ngIf]="isStatus">
... line of code...
</ng-template>
但是不建议按照每个角度社区(Angular structural guide)
其他方法是您可以将其包装到div或span标签中,如下所示:-
<div *ngIf="hero.sample">
Section {{hero.sample}} ,
</div>
但是最好的方法是用ng-container
包装:-
<ng-container *ngIf="hero.demo">
Section {{hero.demo}} ,
</ng-container>
要获取有关结构指令的更多详细信息,请访问此链接:- Angular Structural Directive Guide