Why HttpParams doesn't work in multiple line in angular 4.3

后端 未结 5 1524
Happy的楠姐
Happy的楠姐 2020-12-05 02:51

From Angular 4.3 they introduced HttpClient instead of Http. in HttpClient I can\'t use URLSearchParams for url query parameter . instead of

5条回答
  •  伪装坚强ぢ
    2020-12-05 03:07

    Since 5.0.0-beta.6 (2017-09-03) new feature(accept object map for HttpClient headers & params) is available.

    Now we can pass object directly instead of HttpParams:

    const params = {
      'a': '1',
      'b': '2'
    };
    
    this.http.get('...', { params })
    

    or instead of HttpHeaders:

    http.get('/url', {
       headers: {'My-Header': 'header value'}
    })
    

提交回复
热议问题