本文整理汇总了TypeScript中@angular/http/src/url_search_params.URLSearchParams.set方法的典型用法代码示例。如果您正苦于以下问题:TypeScript URLSearchParams.set方法的具体用法?TypeScript URLSearchParams.set怎么用?TypeScript URLSearchParams.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@angular/http/src/url_search_params.URLSearchParams
的用法示例。
在下文中一共展示了URLSearchParams.set方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it('should not encode allowed characters', () => {
/*
* https://tools.ietf.org/html/rfc3986#section-3.4
* Allowed: ( pchar / "/" / "?" )
* pchar: unreserved / pct-encoded / sub-delims / ":" / "@"
* unreserved: ALPHA / DIGIT / "-" / "." / "_" / "~"
* pct-encoded: "%" HEXDIG HEXDIG
* sub-delims: "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
*
* & and = are excluded and should be encoded inside keys and values
* because URLSearchParams is responsible for inserting this.
**/
let params = new URLSearchParams();
'! $ \' ( ) * + , ; A 9 - . _ ~ ? / ='.split(' ').forEach(
(char, idx) => { params.set(`a${idx}`, char); });
expect(params.toString())
.toBe(
`a0=!&a1=$&a2=\'&a3=(&a4=)&a5=*&a6=+&a7=,&a8=;&a9=A&a10=9&a11=-&a12=.&a13=_&a14=~&a15=?&a16=/&a17==`
.replace(/\s/g, ''));
// Original example from https://github.com/angular/angular/issues/9348 for posterity
params = new URLSearchParams();
params.set('q', 'repo:janbaer/howcani+type:issue');
params.set('sort', 'created');
params.set('order', 'desc');
params.set('page', '1');
expect(params.toString())
.toBe('q=repo:janbaer/howcani+type:issue&sort=created&order=desc&page=1');
});
示例2:
(char, idx) => { params.set(`a${idx}`, char); });