angular2-http

Angular2 watch for 302 redirect when fetching resource

人盡茶涼 提交于 2019-11-26 17:23:50
问题 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:/

Angular - POST uploaded file

雨燕双飞 提交于 2019-11-26 17:09:33
I'm using Angular , TypeScript to send a file, along with JSON Data to a server. Below is my code: import {Component, View, NgFor, FORM_DIRECTIVES, FormBuilder, ControlGroup} from 'angular2/angular2'; import {Http, Response, Headers} from 'http/http'; @Component({ selector: 'file-upload' }) @View({ directives: [FORM_DIRECTIVES], template: ` <h3>File Upload</h3> <div> Select file: <input type="file" (change)="changeListener($event)"> </div> ` }) export class FileUploadCmp { public file: File; public url: string; headers: Headers; constructor(public http: Http) { console.log('file upload

Angular 2 Http, Observables and recursive requests

早过忘川 提交于 2019-11-26 16:55:32
问题 I have a REST endpoint that returns a list of items, max 1000 items at a time. If there are more than 1000 items, the response has HTTP status 206 and there's a Next-Range header that I can use in my next request for getting more items. I'm working on an Angular 2 application and trying to implement this with Http and Observable . My problem is that I don't know how to merge multiple Observable s depending on how many pages of items there are and finally return one Observable that my

Angular2: How to load data before rendering the component?

混江龙づ霸主 提交于 2019-11-26 14:55:47
I am trying to load an event from my API before the component gets rendered. Currently I am using my API service which I call from the ngOnInit function of the component. My EventRegister component: import {Component, OnInit, ElementRef} from "angular2/core"; import {ApiService} from "../../services/api.service"; import {EventModel} from '../../models/EventModel'; import {Router, ROUTER_DIRECTIVES, ROUTER_PROVIDERS, RouteConfig, RouteParams, RouterLink} from 'angular2/router'; import {FORM_PROVIDERS, FORM_DIRECTIVES, Control} from 'angular2/common'; @Component({ selector: "register",

Angular: Typescript casting JSON response as object model not working

霸气de小男生 提交于 2019-11-26 14:50:07
问题 I have an issue while I try to cast a json response to object, all the properties of my object are string is that normal ? Here is my ajax request : public getSingle = (keys: any[]): Observable<Badge> => { return this._http.get(this.actionUrl + this.getKeysUrl(keys)) .map((response: Response) => response.json() as Badge ) .catch(this.handleError); } Here is my badge model : export interface Badge { badgeNumber: number; authorizationLevel: number; endOfValidity: Date; } And here is where I

Set base url for angular 2 http requests

有些话、适合烂在心里 提交于 2019-11-26 12:14:06
问题 I am trying to set base url for all my angular 2 http requests. Following is the basic set up for my application. class HttpOptions extends BaseRequestOptions { url:string = \"http://10.7.18.21:8080/api/\"; } bootstrap(AppComponent, [ HTTP_PROVIDERS, provide(RequestOptions, {useClass: HttpOptions}) ]); export class AppComponent { users:Array<User> constructor(private http: Http) { http.get(\"/users\") .subscribe(res => this.users = res.json()); } } The request is not sent to http://10.7.18.21

Angular: Cannot find a differ supporting object &#39;[object Object]&#39;

偶尔善良 提交于 2019-11-26 11:25:30
Im following this tutorial . On the way to get list of users from api.github Im getting error: Cannot find a differ supporting object '[object Object]' I think its related to <ul> <li *ngFor = "#user of users"> {{user | json}} </li> </ul> In my code because before it there was no any error, and im unsure if data come from get request, just clicking didnt give any error, here is my code so far @Component({ selector: 'router', pipes : [], template: ` <div> <form [ngFormModel] = "searchform"> <input type = 'text' [ngFormControl]= 'input1'/> </form> <button (click) = "getusers()">Submit</button> <

File Upload with Angular2 to REST API

给你一囗甜甜゛ 提交于 2019-11-26 06:58:05
问题 Actually, I\'m working on a Spring REST API with an interface coded in Angular 2. My problem is I can\'t upload a file with Angular 2. My Webresources in java is that : @RequestMapping(method = RequestMethod.POST, value = \"/upload\") public String handleFileUpload(@RequestParam MultipartFile file) { //Dosomething } And it is perfectly working when I call it through URL request with Auth header etc ... ( with Advanced Rest Client extension for Chrome ) Proof: (everything works fine in that

Angular - POST uploaded file

谁说胖子不能爱 提交于 2019-11-26 05:15:57
问题 I\'m using Angular, TypeScript to send a file, along with JSON Data to a server. Below is my code: import {Component, View, NgFor, FORM_DIRECTIVES, FormBuilder, ControlGroup} from \'angular2/angular2\'; import {Http, Response, Headers} from \'http/http\'; @Component({ selector: \'file-upload\' }) @View({ directives: [FORM_DIRECTIVES], template: ` <h3>File Upload</h3> <div> Select file: <input type=\"file\" (change)=\"changeListener($event)\"> </div> ` }) export class FileUploadCmp { public

Angular2: How to load data before rendering the component?

自古美人都是妖i 提交于 2019-11-26 03:47:35
问题 I am trying to load an event from my API before the component gets rendered. Currently I am using my API service which I call from the ngOnInit function of the component. My EventRegister component: import {Component, OnInit, ElementRef} from \"angular2/core\"; import {ApiService} from \"../../services/api.service\"; import {EventModel} from \'../../models/EventModel\'; import {Router, ROUTER_DIRECTIVES, ROUTER_PROVIDERS, RouteConfig, RouteParams, RouterLink} from \'angular2/router\'; import