[英]Angular 2 get request response
我正在嘗試處理成功和失敗從響應中返回,當我在文學中得到回應時它會給我控制器中的錯誤
這是我的服務代碼
authentication(userName : string, password:string){
return this.http.get(this.url).map(data=>{
data.json()
});
這是我的控制器代碼
this.authenticationservice.authentication(this.UserName, this.Password)
.subscribe(
response => {
console.log(response);
if (response.status != null) {
switch (response.status) {
case 'Success':
this.response = response.message;
console.log(this.response);
break;
case 'Failure':
this.response = response.message;
this.loginStat = true;
break;
}
}
})
它給出了我的錯誤響應.status和response.message
您需要從map
響應中返回一些內容:
authentication(userName : string, password:string){
return this.http.get(this.url).map(data=>{
return data.json(); //<-- return this
});
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.