代码之家  ›  专栏  ›  技术社区  ›  Ricardo Rocha

Angular:HttpParams类上的解释参数类型[param:string]:string | string[];

  •  0
  • Ricardo Rocha  · 技术社区  · 6 年前

    我使用的HttpParams是以下构造函数:

    constructor(options?: {
            fromString?: string | undefined;
            fromObject?: {
                [param: string]: string | string[];
            } | undefined;
            encoder?: HttpParameterCodec | undefined;
    });
    

    romObject?: {
         [param: string]: string | string[];
    } | undefined;
    
    1 回复  |  直到 6 年前
        1
  •  5
  •   Andrei Tătar    6 年前

    fromObject string|string[] ),也可以是 undefined .

    const params = new HttpParams({fromObject: {bla: 'test'}});
    const params = new HttpParams({fromObject: {bla: ['test1', 'test2']}});
    const params = new HttpParams({fromObject: undefined});
    const params = new HttpParams({});
    

    无效:

    const params = new HttpParams({fromObject: 'this will fail'});