我使用的是以下构造函数HttpParams:
constructor(options?: {
fromString?: string | undefined;
fromObject?: {
[param: string]: string | string[];
} | undefined;
encoder?: HttpParameterCodec | undefined;
});
任何人都可以从我的平面上理解fromObject参数的含义以及如何使用它吗?
romObject?: {
[param: string]: string | string[];
} | undefined;
答案 0 :(得分:2)
它是构造函数的options参数中的可选参数。
这意味着选项(在构造函数中传递)可以具有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'});