I am new to Angular
, but I have to modify existing code.
The idea is that there is a flag (showFeature
). Previously, it was just static boolean value, however now it is more complicated.
@Input() isAccepted: boolean;
constructor(private myService: MyService) { }
...
showFeature() {
this.myService.showFlagPromise().then((isOn: boolean) => {
return (this.isAccepted === true) && isOn
});
return true;
}
import { Injectable } from '@angular/core';
import { HttpService } from './http.service';
@Injectable({
providedIn: 'root'
})
export class MyService {
constructor(private http: HttpService) {
}
showFlagPromise() {
return this.http.get<boolean>("/showFlagPromise").toPromise();
}
}
HTML for this:
<div [hidden]="!showFeature()"> Some button here </div>
Here I have a problem that call to this.myService.showFlagPromise
is done infinitely. There is infinite calls to backend API. I understand that this is because each time Angular tries to updated value of showFeature
that is used in html
to show or hide some part of code.
What is the right way to fix it?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…