我目前正在尝试在我的 app.component.html 文件中使用 ng-if 指令:
<p>This should appear.</p>
<p ng-if="0==1">This shouldn't, but it does.</p>
我的 app.component.ts 文件如下所示:
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html'
})
export class AppComponent {
}
我尝试了许多不同的值0==1
,但它仍然不起作用,包括使用传入变量的值。它正在编译和显示没有错误,但没有删除第二个p
.
我也试过了*ng-if
。当我这样做时,我收到一个错误:
Template parse errors:
Can't bind to 'ng-if' since it isn't a known property of 'p'. ("<p>This should appear.</p>
<p [ERROR ->]*ng-if="0==1">This shouldn't, but it does.</p>
"): ng:///AppModule/AppComponent.html@2:3
Property binding ng-if not used by any directive on an embedded template.
Make sure that the property name is spelled correctly and all directives are listed in the "@NgModule.declarations". ("<p>This should appear.</p>