[英]how can i get Observable value in return string
我是新來的請幫助我如何從服務中獲取組件中的返回值
服務.ts
name:string = 'John';
GetSecureTokene(_hero:Users){
debugger;
if(_hero.Email=='abc' && _hero.PassWord==123){
return this.name;
}
組件.ts
submitForm(vale:any){
debugger;
this._AuthServiceService.GetSecureTokene(vale).subscribe----
//Here how can i Get name from service
}
將代碼從您的服務更改為此
import { of, Observable } from "rxjs";
GetSecureTokene(_hero:Users): Observable<string> {
if(_hero.Email=='abc' && _hero.PassWord==123){
return of(this.name);
}
}
在你的組件中
submitForm(vale:any) {
this._AuthServiceService.GetSecureTokene(vale).subscribe(res => {
console.log(res);
})
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.