angular2-http

Read buffered response with Angular2/RxJS

牧云@^-^@ 提交于 2020-01-03 19:59:59
问题 I'm building a website that reads data from a backend. That data is computed on-the-fly and sent back to the client in a buffered manner. I.e. as soon as the first chunk is computed it is sent to the client, then it computes the next chunk and sends that to the client. This whole process happens in the same HTTP request. The client should not wait for the complete response to finish but handle each chunk by its own as soon as has been sent. Such responses can usually be consumed using the XHR

Read buffered response with Angular2/RxJS

倾然丶 夕夏残阳落幕 提交于 2020-01-03 19:59:50
问题 I'm building a website that reads data from a backend. That data is computed on-the-fly and sent back to the client in a buffered manner. I.e. as soon as the first chunk is computed it is sent to the client, then it computes the next chunk and sends that to the client. This whole process happens in the same HTTP request. The client should not wait for the complete response to finish but handle each chunk by its own as soon as has been sent. Such responses can usually be consumed using the XHR

Angular2 Provide Custom Http Not Working

只谈情不闲聊 提交于 2020-01-03 17:35:11
问题 We need a global space to capture http 401,403, and 500 responses. I looked at a few tutorials and tried an approach of extending http. Here is my custom HTTP (largely copied from online) import { Http, ConnectionBackend, Request, RequestOptions, RequestOptionsArgs, Response, Headers} from '@angular/http'; import { Router} from '@angular/router'; import { Injectable} from '@angular/core'; import { Observable} from 'rxjs/Rx'; @Injectable() export class CustomHttp extends Http { constructor

Open InAppBrowser with Authorization Header

折月煮酒 提交于 2019-12-24 13:39:38
问题 For my Ionic2 app i have a requirement of downloading invoices but only for authenticated users. Is there any way to do it? I have installed the InAppBrowser cordova plugin but it seems like it cannot be used for sending Authorization Header with request. 回答1: This work for me: Look for the (YourProject)\plugins\cordova-plugin-inappbrowser\src\android\InAppBrowser.java file and edit it. In the onReceivedHttpAuthRequest at the end of the file you should put something like this. public void

Managing user authenticated state on manual URL navigation

心不动则不痛 提交于 2019-12-24 00:33:52
问题 I'm using Angular2 with ASP.NET Core MVC and managing manual URL navigation works fine, the server is loading my Home view with Angular2 successfully. On user authentication, I'm setting up a session variable like this : HttpHelper.HttpContext.Session.SetString("isLoggedIn", true.ToString() ); What I want is that after the user is in the application, if somewhat he wants to load a specific route by manually navigating to it, I want my service to call my ASP Controller to check if the user

Observable Map function not running (Angular2, http)

我怕爱的太早我们不能终老 提交于 2019-12-23 08:51:42
问题 Update The issue seems to be that the map function is not run on a "failed" request. This means that if the API I'm talking to returns a 422 Validation Failed error (or other 4xx errors) Angular will treat this as a failure and cause the Observer to run the subscribed error callback, skipping the map function in the process. Is it possible to force Angular to treat certain 4xx errors as successful requests, or force the map function to run even when an Observable returns an error? I have the

How to submit a form using angular 2 http post function using javascript?

不打扰是莪最后的温柔 提交于 2019-12-23 07:38:40
问题 I've started to learning Angular2 but I want to submit a form using http.post() to my Web API but I can't. 回答1: Within your component, you simply need to attach a listener on the submit event and leverage the http object to execute the HTTP request. This object was previously injected into the constructor of the component. var Cmp = ng.core. Component({ selector: 'cmp' template: ` <form (submit)="submitForm()"> <input [(ngModel)]="element.name"/> <button type="submit">Submit the form</button>

Angular 2 “No provider for String!”

怎甘沉沦 提交于 2019-12-22 12:58:56
问题 I'm trying to create a generalized data service in Angular 2, and I'm encountering a strange error. Essentially, I'm creating an HTTP service whose methods take in part of the api url so that I can use it for multiple cases. For example, I would like to pass in 'projects/' and join it with 'api/' to get 'api/projects/' which I could then use in the http calls. My current dataService.ts: import { Injectable } from '@angular/core'; import { Http, Response, Headers } from '@angular/http'; import

How to properly download excel file with Angular2

浪子不回头ぞ 提交于 2019-12-21 05:00:14
问题 This is the code of my service which makes post request with response an xls file : exportInternalOrder(body) { let user_token: string = this.sessionService.getToken(); let headers = new Headers(); headers.append('responseType', 'arraybuffer'); headers.append('Authorization', 'Bearer ' + user_token); return this.http.post(this.config.exportInternalOrder, body,{ headers: headers }).map(res => new Blob([res._body],{ type: 'application/vnd.ms-excel' })); } Which is supposed to handle response of

Cannot find module './in-memory-data-service' in tour of heroes for Angular2

吃可爱长大的小学妹 提交于 2019-12-21 03:11:10
问题 I am trying to work through the Angular2 tour of heroes app, and am running into bugs on the Http section of the tutorial. At first I was getting the error: Cannot find module 'angular2-in-memory-web-api' But fixed that using the information from this question. However, at this same step I'm also getting the following error: app/app.module.ts(10,38): error TS2307: Cannot find module './in-memory-data-service'. I've triple checked and I believe both my in-memory-data-service.ts file and my app