我正在尝试编码一个非常复杂的字符串,以便我可以将它包含在mailto中:
零件:
<a href="mailto:[email protected]?subject='Hello'&{{body}}">
TS:
import { HttpParameterCodec } from "@angular/common/http";
let body = encodeValue('This is the example body\nIt has line breaks and bullets\n\u2022bullet one\n\u2022bullet two\n\u2022bullet three')
当我尝试使用encodeValue时,我得到“找不到名称encodeValue。
如何最好的url编码身体?
HttpParameterCodec
:是用于编码和解码URL中的参数的编解码器(由HttpParams使用)。
如果您需要对Url进行编码,可以使用以下内容:
encodeURI
假设输入是一个完整的URI,可能有一些需要编码的字符。
encodeURIComponent
将编码具有特殊含义的所有内容,因此您将其用于URI的组件,例如:
var textSample= "A sentence with symbols & characters that have special meaning?";
var uri = 'http://example.com/foo?hello=' + encodeURIComponent(textSample);