在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML5/ Angular5 http get方式請求接口數(shù)據(jù)時(shí)如何批量設(shè)置傳遞的參數(shù)?

Angular5 http get方式請求接口數(shù)據(jù)時(shí)如何批量設(shè)置傳遞的參數(shù)?

最近準(zhǔn)備把a(bǔ)ngularjs1.x的項(xiàng)目逐步重構(gòu)升級到angular5。在摸索http的時(shí)候有些疑問。

如get方法,有多個(gè)參數(shù)的時(shí)候有沒有類似于ng1.x的$http那樣的,把參數(shù)放到一個(gè)對象里給params就能批量傳遞的方法呢?

this.heroesUrl
this.http.get(this.heroesUrl)
             .toPromise()
             .then(response => response.json().data as Hero[])
             .catch(this.handleError);
回答
編輯回答
氕氘氚

有啊,第二個(gè)參數(shù)就是傳遞一個(gè)大的對象,其中有{params:xxx}

這是我ng4的一段get封裝,5也應(yīng)該差不多吧。

 public get(url: string, body: any, cb, options) {
    const ops = Object.assign({}, {params: body}, options);
    this.http.get(url, ops).subscribe(data => {
      this.format(data, cb, options.notload);
    });
  }
2017年10月31日 00:52