While working on my Angular 2 project with TypeScript, I encountered an issue where I am attempting to send an arithmetic operation such as 2+4
through an http get request. The expected response from the back-end should be 6
.
However, the problem arises when the +
sign is interpreted as a space character by the back-end, leading to receiving 2 4
instead of 2+4
, causing the operator to be omitted.
I am seeking advice on how to properly encode my query to ensure that it reaches the back-end accurately and without any interpretation errors.
Below is an excerpt of my HttpService for sending the http get request:
@Injectable()
export class HttpService {
constructor(private http:Http) { }
getAnswer(par:string){
const query=par;
console.log("value is:"+par);
return this.http.get('http://localhost:8080/?question='+query).map((res)=>res.text());
}
}