第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

angular2.0封裝http請求服務(wù),拿不到返回結(jié)果?

angular2.0封裝http請求服務(wù),拿不到返回結(jié)果?

app.module.tsimport?{HttpModule}from?'@angular/http'; import?{Demo26Component}?from?'./demo26_http/demo26.component'; import?{MyHttpService}?from?'./demo26_http/myhttp.service'; @NgModule({ ????imports:?[HttpModule,BrowserModule,?FormsModule,?AppRoutingModule], ?????declarations:?[Demo26Component], ?????bootstrap:?[AppComponent], ?????providers:[MyHttpService] }) export?class?AppModule?{?}app.router.tsimport?{?Demo26Component?}?from?'./demo26_http/demo26.component'; const?routes:?Routes?=?[ ??????{?path:?'',?redirectTo:?'/demo26',?pathMatch:?'full'?}, ??????{?path:?'demo26',?component:?Demo26Component?},\ ] @NgModule({????i ????mports:?[RouterModule.forRoot(routes)], ????exports:?[RouterModule] }) export?class?AppRoutingModule?{?}demo26.component.tsimport?{Component,OnInit}?from?'@angular/core'; import{MyHttpService}?from?'./myhttp.service'; @Component({ ????selector:'demo26', ????template:` ????????<h2>demo26,封裝http請求的封裝<h2> ????????<button?(click)="handleClick()">加載更多</button> ????` }) export?class?Demo26Component?implements?OnInit{ ????//myList:Array<any>=[]; ????myList:any[]=[]; ????constructor(private?myService:MyHttpService){} ????ngOnInit(){} ?????handleClick(){ ?????????//向服務(wù)器發(fā)請求 ?????????console.log(1111); ??????????this.myService.sendRequest('http://jsonplaceholder.typicode.com/users').subscribe((result:any)=>{ ??????????????console.log(result); ??????????}) ?????} }myhttp.service.tsimport?{Injectable}from?'@angular/core'; import?{Http,Response}?from?'@angular/http'; import?{Observable}?from?'rxjs/Observable'; import?'rxjs/add/operator/map'; import?'rxjs/add/operator/catch'; @Injectable() export?class?MyHttpService{ ????constructor(private?http:Http){} ????//定義了一個方法是向myUrl對應(yīng)的服務(wù)器端發(fā)送請求 ????sendRequest(myUrl:string){ ????????return?this.http.get(myUrl) ????????????.map((response:?Response)?=>?{ ????????????????response.json(); ????????}) ????} }請問下,為何拿不到返回結(jié)果, 控制臺輸出結(jié)果是undefined.
查看完整描述

1 回答

?
流疊

TA貢獻(xiàn)1條經(jīng)驗 獲得超0個贊

試試這樣

return?this.http.get(myUrl).pipe(
????map((response:?Response)?=>?{
????????response.json();
????}));

我不明白為什么你的http get返回的Observable類型還能有map方法

查看完整回答
反對 回復(fù) 2019-09-25
  • 1 回答
  • 0 關(guān)注
  • 982 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號