У меня есть два компонента, оба из которых имеют значение OnPush
. Родительский компонент устанавливает для accountLoading
значение true после вызова getAccount()
, а затем устанавливает для accountLoading
значение false после завершения вызова. Как и ожидалось, консоль выводит:
this.accountLoading true
с последующим:
this.accountLoading false
Тем не менее, шаблон не обновляется и застревает, думая, что accountLoading
верно. Как мне заставить шаблон обновляться должным образом при изменении значения? Я бы хотел сохранить обнаружение изменений как OnPush.
Родительский компонент:
Машинопись:
public accountLoading: boolean;
...
getAccount() {
this.accountLoading = true;
this.authStore
.pipe(select(fromAuthStore.getAccountData))
.subscribe(account => {
if (account) {
this.accountLoading = false;
}
console.log('this.accountLoading', this.accountLoading);
});
// Loading account if it hasn't yet been loaded
this.authService.getAccount();
}
HTML:
<child-component
[accountLoading]="accountLoading">
</child-component>
Дочерний компонент:
Машинопись:
@Input() accountLoading: boolean;
...
HTML:
<p *ngIf="accountLoading">
Loading...
</p>