我正在使用 Rxjs 和 Angular Framework 开发一个前端项目,我想从 api“api/data_processor_classlib.php....”获取 json 数据。HTML 中通过 this.webProtectionHTML$ 订阅了三个部分。我不知道为什么管道 this.webProtectionHTML$ 发出了 3 次请求。有没有一种可能的解决方案,只需发送一个请求并更新 HTML 中的所有数据?谢谢。
HTML 代码:
<div class="tr">
<div class="align-left">Phishing & Other Frauds</div>
<div class="align-right">{{ (webProtectionHTML$|async)?.phishing}}</div>
</div>
<div class="tr">
<div class="align-left">Spam URLs</div>
<div class="align-right">{{ (webProtectionHTML$|async)?.spamURLs}}</div>
</div>
<div class="tr">
<div class="align-left">Malware Sites</div>
<div class="align-right">{{ (webProtectionHTML$|async)?.malware}}</div>
</div>
Run Code Online (Sandbox Code Playgroud)
成分:
this.webProtectionHTML$ = this.dayService$
.pipe(
mergeMap((days: DaysPeriod // params added to request url) => this.httpClient.get(`api/data_processor_classlib.php....`//request url, { responseType: 'text' })),
map((html: string) => {
//get html code and find data return …Run Code Online (Sandbox Code Playgroud)