我正在使用 Angular 7(有一天我必须升级我的版本)。我有一项服务,其中一些变量可以根据某些变量Promise
(http GET
、PUT
、 ... 响应)而改变。
我希望在模板上打印这些变量。
我可以这样做:
app.component.html:
<ng-container *ngIf="this.dogService.isWarningProblem">
<ngb-alert [dismissible]="false" type="warning" style="text-align: center">
{{this.dogService.errorMessage}}
</ngb-alert>
</ng-container>
app.service.ts:
export class DraftService {
public errorMessage: string;
public isWarningProblem: boolean;
constructor
(
private generalErrorService: GeneralErrorService,
private http: HttpClient
) {
[...]
}
public launchPingEditReadDraftByActionOfferIdUrl(action: string, offerIdUrl: string): Subscription {
return interval(10).subscribe(
() => {
//Get variables from the server and set them.
},
() => {}
);
}
}
我希望使用服务,因为算法等于另一个组件,但他们看不到其他组件的变量。因此,我不能将订阅与 Behavior Subject 和 Observable 一起使用:
有没有更好的解决方案?