angular-http

Angular - append params to URL

亡梦爱人 提交于 2021-02-10 15:15:59
问题 I would like to append parameters to url: let params = []; params["p1"] = "value1"; params["p2"] = "value2"; this.location.go(this.router.createUrlTree([this.data]).toString()); When I have this url localhost/project/page its work correct. But when I have url localhost/project/page/id after append url is localhost/project/page/p1=.. I need to keep the parameter in url and add the new one. thanks for advices 回答1: When you click the button, call a method like the one below? Here this.router is

Angular - append params to URL

倾然丶 夕夏残阳落幕 提交于 2021-02-10 15:15:23
问题 I would like to append parameters to url: let params = []; params["p1"] = "value1"; params["p2"] = "value2"; this.location.go(this.router.createUrlTree([this.data]).toString()); When I have this url localhost/project/page its work correct. But when I have url localhost/project/page/id after append url is localhost/project/page/p1=.. I need to keep the parameter in url and add the new one. thanks for advices 回答1: When you click the button, call a method like the one below? Here this.router is

Angular 2 HTTP Headers not being added to request

我们两清 提交于 2021-02-09 10:56:48
问题 I have the following http request in which I add the header to the request, however the request fails and when I look in the Network tab of the browser the request headers don't include the Authorization header. What am I missing here?: public get(address: string, callback: any): Observable<any> { let headers: Headers = new Headers(); headers.append('Authorization', 'Bearer <token>'); return this.http.get(address, { 'Headers': headers }) .map(callback) .catch((error: any) => this.handleError

Angular 2 HTTP Headers not being added to request

心不动则不痛 提交于 2021-02-09 10:53:01
问题 I have the following http request in which I add the header to the request, however the request fails and when I look in the Network tab of the browser the request headers don't include the Authorization header. What am I missing here?: public get(address: string, callback: any): Observable<any> { let headers: Headers = new Headers(); headers.append('Authorization', 'Bearer <token>'); return this.http.get(address, { 'Headers': headers }) .map(callback) .catch((error: any) => this.handleError

post request with form-data from angular to spring

末鹿安然 提交于 2021-01-29 06:48:48
问题 i am trying to send a post request to my spring rest api using angular and its http library. currently in post-man (sucessfully) i am sending the data in this way: The format is form-data The key is reqData(mandatory) The Value is json(mandatory) how to send the data in the same way via angular? currently, this is how my data looks like: onSignIn(form: NgForm) { const email = form.value.email; const password = form.value.password; const reqData = { 'app_uname': email, 'app_pass': password };

Angular Testing Getting Actual HTTP Response

别说谁变了你拦得住时间么 提交于 2021-01-27 19:46:29
问题 I'm new to angular unit testing. What I want to do is getting actual results from my API. I checked this documentation but as I understand, I should create mock responses. Here is my code, myService.ts: ... public GetAll = (apiname: string): Observable<Object> => { return this._http.get("foo/" + apiname,{headers:this.options}); //this.options = newHttpHeaders({'ContentType':'application/json','Accept':'application/json'}); } ... myService.spec.ts: ... beforeEach(() => { TestBed

Angular http get not working and no error thrown

谁说我不能喝 提交于 2020-07-10 17:29:05
问题 There are lot questions around this topic but I could not find a suitable solution. I am not able to see any error on the console, which is why its very confusing. here is my service file code findVariantById(id: string):Observable<Evaluation[]> { const endPoint = 'Evalution/Get' let params = new URLSearchParams(); params.set('key', '1234'); //For example API key would come into picture params.set('id', id); params.set('format', 'json'); params.set('callback', 'JSONP_CALLBACK'); // this much

Angular http get not working and no error thrown

左心房为你撑大大i 提交于 2020-07-10 17:28:06
问题 There are lot questions around this topic but I could not find a suitable solution. I am not able to see any error on the console, which is why its very confusing. here is my service file code findVariantById(id: string):Observable<Evaluation[]> { const endPoint = 'Evalution/Get' let params = new URLSearchParams(); params.set('key', '1234'); //For example API key would come into picture params.set('id', id); params.set('format', 'json'); params.set('callback', 'JSONP_CALLBACK'); // this much

How to propagate errors through catchError() properly?

柔情痞子 提交于 2020-05-10 03:58:50
问题 I wrote a function that is pipe -able: HandleHttpBasicError<T>() { return ((source:Observable<T>) => { return source.pipe( catchError((err:any) => { let msg = ''; if(err && err instanceof HttpErrorResponse) { if(err.status == 0) msg += "The server didn't respond"; } throw { err, msg } as CustomError }) ) }) } I can use this function this way in my HttpService : checkExist(id:string) { return this.http.head<void>(environment.apiUrl + 'some_url/' + id) .pipe( HandleHttpBasicError(), catchError(

How to propagate errors through catchError() properly?

送分小仙女□ 提交于 2020-05-10 03:58:05
问题 I wrote a function that is pipe -able: HandleHttpBasicError<T>() { return ((source:Observable<T>) => { return source.pipe( catchError((err:any) => { let msg = ''; if(err && err instanceof HttpErrorResponse) { if(err.status == 0) msg += "The server didn't respond"; } throw { err, msg } as CustomError }) ) }) } I can use this function this way in my HttpService : checkExist(id:string) { return this.http.head<void>(environment.apiUrl + 'some_url/' + id) .pipe( HandleHttpBasicError(), catchError(