typescript-angular.encoder.mustache Maven / Gradle / Ivy
{{#useHttpClient}}
import { HttpUrlEncodingCodec } from '@angular/common/http';
{{/useHttpClient}}
{{^useHttpClient}}
import { QueryEncoder } from '@angular/http';
{{/useHttpClient}}
{{#useHttpClient}}
/**
* CustomHttpUrlEncodingCodec
* Fix plus sign (+) not encoding, so sent as blank space
* See: https://github.com/angular/angular/issues/11058#issuecomment-247367318
*/
export class CustomHttpUrlEncodingCodec extends HttpUrlEncodingCodec {
encodeKey(k: string): string {
k = super.encodeKey(k);
return k.replace(/\+/gi, '%2B');
}
encodeValue(v: string): string {
v = super.encodeValue(v);
return v.replace(/\+/gi, '%2B');
}
}
{{/useHttpClient}}
{{^useHttpClient}}
/**
* CustomQueryEncoderHelper
* Fix plus sign (+) not encoding, so sent as blank space
* See: https://github.com/angular/angular/issues/11058#issuecomment-247367318
*/
export class CustomQueryEncoderHelper extends QueryEncoder {
encodeKey(k: string): string {
k = super.encodeKey(k);
return k.replace(/\+/gi, '%2B');
}
encodeValue(v: string): string {
v = super.encodeValue(v);
return v.replace(/\+/gi, '%2B');
}
}
{{/useHttpClient}}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy