angular-httpclient

Importing HttpClientModule in feature modules

一世执手 提交于 2019-12-11 19:44:58
问题 The docs on HttpClientModule say: Before you can use the HttpClientModule, you need to import the Angular HttpClientModule. Most apps do so in the root AppModule. In which cases we want to import the HttpClientModule into feature modules? What would happen if we imported it into multiple feature modules which, in turn, are impoted into the root module? Is this a proper use case of it when we have dozens of modules in an app, a few of which need HttpClientModule , and we would like to import

Angular httpClient headers

可紊 提交于 2019-12-11 18:08:07
问题 Below is my HTTP post request to get the auth token, the headers are not getting set, in chrome I don't see the headers under request headers. What I also observed is, if I add only the content-type header I can see the header and body being sent in the request, if I add authorization header then no header or body being sent in the request and I see Response to preflight has invalid HTTP status code 401. error on console. I also tried enabling "CORS" still the same issue. have tried all the

Proxy to multiple paths angular

十年热恋 提交于 2019-12-11 16:56:41
问题 I'm trying to proxy to a certain API endpoint that returns an html page but I get the error Access to font at 'https://data.domain.com/v3/assets/fonts/glyphicons-halflings-regular.woff2' from origin 'http://localhost:4200' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. GET https://data.domain.com/v3/assets/fonts/glyphicons-halflings-regular.woff2 net::ERR_FAILED Inside my angular app, I have three different targets that I am

Angular HttpClient replacement for RequestOptions?

心不动则不痛 提交于 2019-12-11 16:36:59
问题 Angular's Http module used to have a RequestOptions object which could be passed to its get method (e.g. this.http.get(fooUrl, barOptions) . The RequestOptions contained any headers. This was deprecated. The "closest replacement" for the deprecated RequestOptions is HttpRequest. There's two problems with this: 1. HttpRequest has a url param, so it is NOT an equivalent of RequestOptions . In fact, it seems to encapsulate the entire request, yet I don't see it used anywhere, so I am guessing it

Using directive with different services in Angular

三世轮回 提交于 2019-12-11 16:36:33
问题 I must be approaching this from a false perspective, but here is the problem. I have an async validation directive which uses HttpClient to validate something with the backend. It is almost independent apart from one critical thing – it needs correct HTTP headers to pass authentication on the server side. This is how the constructor looks: constructor( private http: HttpClient, private auth: AuthService, @Optional() @Self() @Inject(NG_VALUE_ACCESSOR) valueAccessors: ControlValueAccessor[] ) {

Angular download node.js response.sendFile

五迷三道 提交于 2019-12-11 16:21:35
问题 At the moment my nodejs service is doing this: ... fs.writeFileSync('filelocation/data.xlsx', theData, 'binary'); reponse.sendFile('filelocation/data.xlsx'); reponse.download('filelocation/data.xlsx'); // I tried this one also ... But now how do I download this from Angular front end using the HttpClient ? This does not work: this.httpclient.get(url).subscribe(response => { console.log(response); // Or whatever I need to do to download the file }); I want the call to bring up the file

Angular: How to map JSON result from HttpClient request to class instances?

杀马特。学长 韩版系。学妹 提交于 2019-12-11 14:44:55
问题 I have the following code which seems wrong: public search(searchString: string): Observable<Array<ClientSearchResult>> { let params = new HttpParams().set('searchString', searchString); return this.http .get<Array<ClientSearchResult>>(this.searchUrl, { params: params }) .map((results: ClientSearchResult[]) => results.map((r: ClientSearchResult) => new ClientSearchResult(r))); } I know that the API is returning a JSON object which is not the same as an instance of my TypeScript class. However

Angular Typescript how to sendi complex json data to web api when model is flat?

泪湿孤枕 提交于 2019-12-11 12:28:16
问题 I have been sending data to a web api that i flat, but now i am needed more complex json object In the past... I was doing this ( It works , web api accepts flat model ) MODEL: export class Menu { constructor( ) { } UserID: number; AppID: number; NavAppID: number; AppGroupID: number; SelectedCaseID: number = 0; SelectedRoleID: number; } Component: model = new Menu(); this.pageService.getPageCommonData(this.model) //(this.model) .subscribe( result => { this.caseCaption = result["data"]

Angular 5 nested http client observables return object

五迷三道 提交于 2019-12-11 11:04:09
问题 I am trying to create an observable response where I make one http call and then before returning the response, I make another http call to populate the return object of the first call as shown below. getOrderWithItems(orderId: string, includes: Set<OrderInclude>): Observable<OrderDto> { return this.getOrder(orderId, includes) .map(order => { this.searchItems().subscribe( items => { order.items = items.results; return order; } ) }); } The compiler gives an error: Type 'Observable' is not

How to change HttpClient code after update app to Angular 7

故事扮演 提交于 2019-12-11 06:20:11
问题 I updated Angular to version 7 into my app and I have to change my code a little bit after update but I'm not sure how to do it. This is example of code to change (in previous version of Angular): get(): Observable<MyResponseClass | null> { let url_ = some_url; let options_: any = { method: "get", headers: new Headers({ "Content-Type": "application/json", "Accept": "application/json" }) }; return this.http.request(url_, options_).flatMap((response_: any) => { return this.getResponse(response_