我正在使用* ngIf在模板中有条件地显示<div>标签。
<div *ngIf="panel?.imageUrl"><img [src]="panel?.imageUrl" /></div>因为我使用TypeScript,如果我没有在@Component指令中声明NgIf,则会出现“编译”时间错误“未使用的NgIf”。 如果我将NgIf添加到ETHER viewProviders或者providers或directives ( directives: [NgIf] ),它会编译并工作。 我的问题是:宣布NgIf的正确方法是什么?为什么?
I am using *ngIf to conditionally display a <div> tag in a template.
<div *ngIf="panel?.imageUrl"><img [src]="panel?.imageUrl" /></div>Because I am using TypeScript, there is a "compile" time error "unused NgIf" if I do not declare NgIf in a @Component directive. It compiles and works if I add NgIf to ETHER viewProviders or providers or directives (directives: [NgIf]). My question is: what is the right way to declare NgIf and why?
最满意答案
无需向提供者添加NgIf 。 它们包含在PLATFORM_DIRECTIVES ,默认情况下可以在任何地方使用。
There is no need to add NgIf to providers. They are included in PLATFORM_DIRECTIVES which are available everywhere by default.
更多推荐
NgIf,ngIf,使用,电脑培训,计算机培训,IT培训"/> <meta name="description"
发布评论