服務實際上從服務器獲得正確的值(例如1或0),但在組件中實現服務時總是返回未定義的值。我認爲return
聲明剛好在.then()
編譯之前編譯。我該如何解決這個問題?此方法總是返回一個未定義的值
private isDuplicateNik(nik: number): boolean{
let count: number;
this.employeeService.isDuplicateNik(nik).then(
res => {
count = res;
}
);
return (count > 0 ? false : true);
}
[承諾後的返回值]的可能重複(https://stackoverflow.com/questions/22951208/return-value-after-a-promise) – jonrsharpe