angular-http

Angular2. Map http response to concrete object instance

梦想的初衷 提交于 2020-01-02 04:46:08
问题 Сommon approach to process http response is like that: return this._http.get(url) .map((res: Response) => res.json()); which provides you with an Observable<Object[]> where Object is dynamically created type from json de-serialization. Then you can use this result in *ngFor="let item of result | async" etc... I'd like to get a specific type instance (meaning using new operator to call the type's constructor). Tried different ways to achieve something like that: .map((res: Response) => { let

Angular2. Map http response to concrete object instance

心不动则不痛 提交于 2020-01-02 04:46:07
问题 Сommon approach to process http response is like that: return this._http.get(url) .map((res: Response) => res.json()); which provides you with an Observable<Object[]> where Object is dynamically created type from json de-serialization. Then you can use this result in *ngFor="let item of result | async" etc... I'd like to get a specific type instance (meaning using new operator to call the type's constructor). Tried different ways to achieve something like that: .map((res: Response) => { let

AngularJS / Alfresco / CORS filter issue: No 'Access-Control-Allow-Origin' header

为君一笑 提交于 2020-01-01 19:29:30
问题 I have some problem with Alfresco (5.0.d) , my AngularJS (1.4.3) client and the CORS settings (typical cross-domain / No'Access-Control-Allow-Origin' header is present on the requested resource problem). I am calling the Alfresco REST API from an AngularJS application running on localhost: 3000 , to an Alfresco instance running on localhost: 8080 (Tomcat, no reverse-proxy in front). This XHR call works fine: http://localhost:8080/alfresco/service/slingshot/live-search-docs?t=Project&u=admin

Angular 2 http post params and body

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-01 02:25:12
问题 I'm trying to do an api call from my angular app. What I want to do is send a post request to the api with a command param. I have done a lot of server side testing as well as going through the outgoing request, and the $_POST nor body data is never there. I am therefore pretty sure that the problem lays within this piece of code. public post(cmd: string, data: object): Observable<any> { const params = new URLSearchParams(); params.set('cmd', cmd); const options = new RequestOptions({ headers

How to handle unauthorized requests(status with 401 or 403) with new httpClient in angular 4.3

血红的双手。 提交于 2019-12-31 15:51:56
问题 I have an auth-interceptor.service.ts to handle the requests import {Injectable} from '@angular/core'; import {HttpErrorResponse, HttpEvent, HttpHandler, HttpInterceptor, HttpRequest} from '@angular/common/http'; import {Observable} from 'rxjs/Observable'; import {Cookie} from './cookie.service'; import {Router} from '@angular/router'; @Injectable() export class AuthInterceptor implements HttpInterceptor { constructor(private router: Router) {} intercept(req: HttpRequest<any>, next:

Cancelling an angular service promise

僤鯓⒐⒋嵵緔 提交于 2019-12-25 09:17:41
问题 I have a controller that performs a http request. This request can take anywhere between 2 seconds to 4 minutes to return some data . I have added a button, that users should click to cancel the request if searches take too long to complete. Controller: $scope.search = function() { myFactory.getResults() .then(function(data) { // some logic }, function(error) { // some logic }); } Service: var myFactory = function($http, $q) { return { getResults: function(data) { var deffered = $q.dafer();

mimicking getJSON in Angular

落爺英雄遲暮 提交于 2019-12-24 16:04:41
问题 I have the following code that works in Angular: $scope.yqlProxy=function(url, done) { $.getJSON("http://query.yahooapis.com/v1/public/yql", { q: 'select * from json where url="'+url+'"', format: "json" }, function(data){ if (data.query.results) { done(data.query.results); } }); }, As the "better" way usually is to use $http I changed the code to this: $scope.yqlProxy=function(url, done) { $http.get("http://query.yahooapis.com/v1/public/yql", { params: { q: 'select * from json where url="' +

How to handle error when implementing Exponential backoff function?

蓝咒 提交于 2019-12-24 15:55:31
问题 I use the concept of the backoff method to retry the request if internal Server Error occurs. I mean not 401 , 403 or similar. My target is to retry the request if the server doesn't respond and/or it takes too long to send a response, for instance in case of pending status. And I do have defined timeout limit for that (in the service). My Issue is that the retryWhen function is being invoked in all the cases/errors including 401 . I believe that I might have to restructure my function/code

Get Subscribe Data out of .subscribe in Angular

喜夏-厌秋 提交于 2019-12-24 14:09:51
问题 I want to return the events after the subscriber is called. getCalendarData(){ var body = JSON.stringify({"cid": "etNG3V61LWS6Pzkeb_omuZGMVAOLd1_70tRQblVizWQ~", "seldt":"2018-09-18"}); var headers = new HttpHeaders(); headers.append('Content-Type', 'application/json'); return this.httpClient.post(this.apiUrl, body, { headers: headers }) } The above code works perfectly. It also returns the JSON. Now the problem is, when I call this method inside the getCalendarEvents(), I failed to return the

Pre-flight Request not triggered for CORS check

江枫思渺然 提交于 2019-12-24 08:19:02
问题 As I understand, a pre-flight request is sent by the browser if any of the following conditions is false (source: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#Simple_requests): Request method is GET, HEAD or POST. Custom headers are not set. Content-Type header value is either application/x-www-form-urlencoded , multipart/form-data or text/plain . I have a web app which sends a GET request to a server on a different origin. Since I have to send cookies to the server, the property