かなり複雑な文字列をエンコードして、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 エンコードするにはどうすればよいでしょうか?
ベストアンサー1
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);