我正在尝试解决问题并编写以下代码以查看发生了什么,但现在我更加困惑。理想情况下如果entry.customer
有值应该打印然后Hello
也应该显示,否则应该显示NOPE
and Goodbye
,但实际结果是只entry.customer
显示的值。
<h3>{{entry.customer}}</h3>
<span *ngIf="entry.customer else no">
<h1>Hello</h1>
</span>
<ng-template #no>
<h1> NOPE</h1>
</ng-template>
<span *ngIf="!entry.customer">
<h1>Goodbye</h1>
</span>
<h3> {{entry.customer}} </h3>
<span *ngIf="entry.customer else no">
<h1>Hello</h1>
</span>
<ng-template #no>
<h1> NOPE</h1>
</ng-template>
<span *ngIf="!entry.customer">
<h1>Goodbye</h1>
</span>
当我开始追踪这个问题时,我认为由于条目的值来自 BehaviorSubject,可能存在更改检测问题,因此我尝试获取区域中的值,但这并没有改变结果。
ngOnInit(): void {
this.ngZone.run(() => {
debugger;
this._entryService.entry.subscribe(entry => {
debugger;
this.entry = entry;
});
})
}
谁能解释 *ngIf 不起作用的可能原因,但使用花括号确实显示了该值?如果它有帮助,我正在使用的任何组件是从获取 entry 值的基本组件扩展而来的,因为此应用程序中有许多相同类型的组件。