getPersonalMast(name:string){
console.log("patient");
this.masterDataService.getPersonalMast(this.staff).subscribe(console.log("Inside subscribe"), response => this.staffInfo = response);
return this.staffInfo;
}
這是主服務稱爲角通話服務兩次
getPersonalMast(personName: String): Observable<PersonalMastModel[]>{
console.log("patientInfo");
let headers = new Headers();
if(personName!= undefined){
headers.append(AppUtils.HEADER_AUTHENTICATION, localStorage.getItem(AppUtils.STORAGE_ACCOUNT_TOKEN));
headers.append('Content-Type','application/json');
headers.append('Access-Control-Allow-Origin', '*');
return this.http.post(AppUtils.GET_PERSONAL_MASTER_URL ,{personName:personName},{headers:headers})
.map(console.log("Inside map"),response => response.json().result)
.catch(this.handleError);
}
}
有了這個服務,每次調用這個服務會導致多次擊中的URL。
每個方法調用=多重服務調用。
爲什麼出現這種情況,我該如何解決這個問題?
調用服務代碼:
<input ng2-auto-complete
[(ngModel)]="staff"
[source]="staffInfo"
placeholder="enter text"
[list-formatter]="listFormatter"
value-property-name="perscode"
display-property-name="personName"
(keypress)="getPersonalMast($event)"
>
您可以顯示調用服務的代碼? – DeborahK
每次組件加載時服務調用的次數是2次,還是第一次調用服務時,第二次調用兩次時,第三次調用三次時等,當您重新加載窗口或重新訪問此組件時? –
@DeborahK更新了問題 – user630209