【发布时间】:2019-08-20 13:38:45
【问题描述】:
我正在尝试对一个非常复杂的字符串进行编码,以便可以将其包含在 mailto 中:
组件:
<a href="mailto:test@example.com?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 编码?
【问题讨论】:
-
首先,您可以使用 JavaScript 的
encodeURI函数来编码您的文本。 (如果您使用的字符之一 -;,/?:@&=+$#,请改用encodeURIComponent函数。) -
这在项目符号或换行符上不起作用
-
它是用于 URI 的