angular2-http

angular 2 http withCredentials

杀马特。学长 韩版系。学妹 提交于 2019-11-28 18:35:37
I'm am trying to use withCredentials to send a cookie along to my service but can't find out how to implement it. The docs say "If the server requires user credentials, we'll enable them in the request headers" With no examples. I have tried several different ways but it still will not send my cookie. Here is my code so far. private systemConnect(token) { let headers = new Headers(); headers.append('Content-Type', 'application/json'); headers.append('X-CSRF-Token', token.token); let options = new RequestOptions({ headers: headers }); this.http.post(this.connectUrl, { withCredentials: true },

Getting an object array from an Angular service

不想你离开。 提交于 2019-11-28 17:36:39
I am new to Angular (and Javascript for that matter). I've written an Angular service which returns an array of users. The data is retrieved from an HTTP call which returns the data in JSON format. When logging the JSON data returned from the HTTP call, I can see that this call is successful and the correct data is returned. I have a component which calls the service to get the users and an HTML page which displays the users. I cannot get the data from the service to the component. I suspect I am using the Observable incorrectly. Maybe I'm using subscribe incorrectly as well. If I comment out

Angular 2 RxJS Observable: RetryWhen filter retry on error Status

放肆的年华 提交于 2019-11-28 12:38:31
I am using Angular 2 HTTP library which returns an observable. I want to implement retry on certain error status/code. I have an issue, if the error is not 429, Observable.of(error) is getting executed in error case to retry, but when all your 2 retry fails the execution of flow goes to success block instead of catch block. How to make execution of flow to catch block in all retry fails? return this.http.get(url,options) .retryWhen((errors) => { return errors .mergeMap((error) => (error.status === 429) ? Observable.throw(error) : Observable.of(error)) .take(2); }) .toPromise() .then((res

Angular 2/4 can't read object in initForm()

不打扰是莪最后的温柔 提交于 2019-11-28 10:33:40
问题 I'm creating an edit form in angular and I'm confused about the lifecycle of the object that is returned from my backend server. When I make a call to my service in ngOnInit() , I get workable data. When I assign that to an instance variable, It is undefined in initForm() even though I'm calling initForm() after assigning that data. If you look at the console.log statements you will see that the object works inside the ngOnInit() function but not in initForm() . What am I missing here? How do

How to use angular2 http API for tracking upload/download progress

那年仲夏 提交于 2019-11-28 05:28:05
Tho there are many adhoc libraries supporting upload/download progress in angular2, I do not know how to do use native angular2 http api to show progress while doing upload/download. The reason why I want to use native http api is because I want to utilise http interceptors(http API wrappers) around native http api that validate, cache & enrich the actual http request being sent such as this & this Besides angular's http api is much more robust than any adhoc APIs There is this nice article about how to do upload/download using angular's http api But the article mentions that there is no

No provider for ConnectionBackend while inheriting from Http

元气小坏坏 提交于 2019-11-28 02:52:06
问题 I am trying to make a wrapper around built in Http service in angular 2 to have a possibility to add custom behaviour (headers, parameters etc.) So I created a usual class (not a service) and inherit it from Http. Class definition import { Http, ConnectionBackend, RequestOptions, RequestOptionsArgs, Headers } from '@angular/http'; import { Observable } from 'rxjs/Observable'; import {tamamApiUrl} from '../constants'; import {CustomQueryEncoder} from './CustomQueryEncoder'; import 'rxjs/Rx';

Get Image or byte data with http

僤鯓⒐⒋嵵緔 提交于 2019-11-27 19:28:55
For a web application I need to get my images with an ajax request because we have signature + authentication on our API, so we can't get images using a simple <img src="myapi/example/145"/> Since we're using angular2, we obviously looked for blob or something like that, but as stated in static_response.d.ts file: /** * Not yet implemented */ blob(): any; So okay, I can't do it for now, I have to wait for thie feature to be implemented. But problem is I can't wait so I need a hotfix or a little hack to be able to get image data from response and I'll be able to remove my hack and set the blob(

How do you POST a FormData object in Angular 2?

最后都变了- 提交于 2019-11-27 18:07:42
I need to upload a file and send some json along with it, I have this function: POST_formData(url, data) { var headers = new Headers(), authtoken = localStorage.getItem('authtoken'); if (authtoken) { headers.append("Authorization", 'Token ' + authtoken) } headers.append("Accept", 'application/json'); headers.delete("Content-Type"); var requestoptions = new RequestOptions({ method: RequestMethod.Post, url: this.apiURL + url, headers: headers, body: data }) return this.http.request(new Request(requestoptions)) .map((res: Response) => { if (res) { return { status: res.status, json: res.json() } }

Angular 2 - Routing - CanActivate work with Observable

雨燕双飞 提交于 2019-11-27 17:02:49
I have an AuthGuard (used for routing) that implements CanActivate . canActivate() { return this.loginService.isLoggedIn(); } My problem is, that the CanActivate-result depends on a http-get-result - the LoginService returns an Observable . isLoggedIn():Observable<boolean> { return this.http.get(ApiResources.LOGON).map(response => response.ok); } How can i bring those together - make CanActivate depend on a backend state? Kery Hu You should upgrade "@angular/router" to the latest . e.g."3.0.0-alpha.8" modify AuthGuard.ts @Injectable() export class AuthGuard implements CanActivate { constructor

Angular2 watch for 302 redirect when fetching resource

廉价感情. 提交于 2019-11-27 16:05:04
I have a requirement to pull a few resources from another domain held by my company. I want to pull secured HTML content with GET requests. When a user is signed out of the application the requested content will return a 302 to the login page. My attempts to sniff the headers for a 302 haven't returned what I'd hoped for so far. The response returned by my Observable is a 200 (login page). Here is my sample app. export class MenuComponent implements OnInit { private _resourceUrl = "http://localhost:3001/resources/menu"; constructor(private _http: Http){ } menu: string; ngOnInit(): void { this