簡體   English   中英

Angular:從錨標記點擊獲得響應后,該方法在每次點擊頁面上的任何控件時一次又一次地調用

[英]Angular : After getting response from anchor tag click , that method call again and again on each click of any control on page

我正在使用 angular 13. 在我的應用程序中,我必須在單擊錨標記時打開 pdf,這樣我就完成了編碼。 但是現在點擊錨標記我得到了 pdf 但在那之后如果我點擊頁面上的任何按鈕/控件,它會在沒有任何正確調用的情況下調用同一頁面。 例如,如果我點擊錨標簽 pdf 獲得下載,然后如果我點擊返回按鈕 pdf 再次獲得下載。

這個generateAppLoad function直接get調用一遍又一遍。

View-apply.component.html
--------------------------


<a (click)="onSendPdf()"> Click on Link</a>

getInformation(){
return combineLatest([
this.Service.EmploymentName,
this.Service.EmploymentCountry,
this.Service.EmploymentEmail,
.....
]);
}

generateAppLoad(EmploymentName,EmploymentCountry,EmploymentEmail,....)
{
const sendAppLoad: SendAppReq = {
application_detail : {
emp_name : EmploymentName.Key,
emp_country:EmploymentCountry.Key
..
},
.
.
application_personal_detail : {
email: EmploymentNameEmail.Key,
phone: EmploymentNamePhone.Key
}

return sendAppLoad;
}


onSendPdf() {
this.getInformation()
.pipe(
map((val1) = this.generateAppLoad(...val1)),
switchMap((param) => this.EmpService.generateForm(param,this.EmpId))
).subscribe({
next:(response) => {
const file - new Blob([response],{type: 'application/pdf'});
const fileURL = URL.createObjectURL(file);
window.open(fileURL);


}
error: (error) => {
console.log('error')
}
})
}

onBackClick () {
this.router.navigateByUrl('/Cont-detail')
}

map((val1) = this.generateAppLoad(...val1)) 這一行一次又一次地調用,我仍然沒有在后退按鈕上調用 onSendPdf。

嘗試將changeDetectionStrategy更改為onPush

 @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'], changeDetection: ChangeDetectionStrategy.OnPush // here it is })

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM