zoukankan      html  css  js  c++  java
  • [Angular] HttpParams

    It is possible to use HttpParams to set http params.

    For example we have this url to make:

    https://angular-http-guide.firebaseio.com/courses.json?orderBy="$key"&limitToFirst=1

    So there are two params:

      1. orderby

      2. limitToFirst

    Using HttpParams:

    import {HttpParams} from "@angular/common/http";
    
    const params = new HttpParams()
        .set('orderBy', '"$key"')
        .set('limitToFirst', "1");
    
    this.courses$ = this.http
        .get("/courses.json", {params})
        .do(console.log)
        .map(data => _.values(data))

    To notice that HttpParams's instance is an immutable object, everytime you call 'set()' method on it, it will create a new object, so you need to use chain method.

    Equivalent way:

    const params = new HttpParams({
      fromString: 'orderBy="$key"&limitToFirst=1'
    });

    Original Article

  • 相关阅读:
    B
    A
    P1057 传球游戏
    P1702 突击考试
    P1394 山上的国度
    P2117 小Z的矩阵
    P1510 精卫填海
    P1294 高手去散步
    P1071 潜伏者
    保留
  • 原文地址:https://www.cnblogs.com/Answer1215/p/7418468.html
Copyright © 2011-2022 走看看