【发布时间】:2018-04-16 20:42:23
【问题描述】:
我目前正尝试在我的 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>
【问题讨论】:
-
在 Angular 2+ 中,它是
*ngIf -
好的,很高兴知道,因为有很多不同的文档在流传。我应该提到,在我已经尝试过的许多事情中,
*ng-if就是其中之一。 -
好的,所以问题不只是星号;我还需要删除连字符并将“i”大写。
标签: angular angular-ng-if angularjs-ng-if