Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

448
Views
Codificar cadena para URL (angular)

Estoy tratando de codificar una cadena que es bastante compleja, para poder incluirla en un mailto:

Componente:

 <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')

Cuando trato de usar encodeValue, aparece "no se puede encontrar el nombre encodeValue.

¿Cómo sería mejor codificar la URL del cuerpo?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

HttpParameterCodec : es un códec para codificar y decodificar parámetros en URL (usado por HttpParams).

Si necesita codificar Url, puede usar lo siguiente:

encodeURI asume que la entrada es un URI completo que puede tener algunos caracteres que necesitan codificación.

encodeURIComponent codificará todo con un significado especial, por lo que lo usa para componentes de URI, como:

 var textSample= "A sentence with symbols & characters that have special meaning?"; var uri = 'http://example.com/foo?hello=' + encodeURIComponent(textSample);
over 4 years ago · Santiago Trujillo Report

0

Tanto encodeURI() como encodeURIComponent() funcionarán, aunque existen algunas diferencias:

 var set1 = ";,/?:@&=+$"; // Reserved Characters var set2 = "-_.!~*'()"; // Unescaped Characters var set3 = "#"; // Number Sign var set4 = "ABC abc 123"; // Alphanumeric Characters + Space console.log(encodeURI(set1)); // ;,/?:@&=+$ console.log(encodeURI(set2)); // -_.!~*'() console.log(encodeURI(set3)); // # console.log(encodeURI(set4)); // ABC%20abc%20123 (the space gets encoded as %20) console.log(encodeURIComponent(set1)); // %3B%2C%2F%3F%3A%40%26%3D%2B%24 console.log(encodeURIComponent(set2)); // -_.!~*'() console.log(encodeURIComponent(set3)); // %23 console.log(encodeURIComponent(set4)); // ABC%20abc%20123 (the space gets encoded as %20)

Referencia: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!