angular-http

Display Subscribe Data in Angular 4

六月ゝ 毕业季﹏ 提交于 2019-12-05 04:10:32
问题 I need help in displaying the output of subscribe from an api in Angular 4. How can i do this since I wrote data.data.data but it says property data doesnt exist on type object. How would i output it in the browser? Here's my code below and the api picture below import { Component, OnInit } from '@angular/core'; import { NewsService } from '../news.service'; @Component({ selector: 'app-news-list', templateUrl: './news-list.component.html', styleUrls: ['./news-list.component.css'] }) export

AngularJS global $http state ajax loader

浪尽此生 提交于 2019-12-04 19:41:22
I have an AngularJS app, and need an ajax loader for every request done by the $http - is there a simple way to do this. My solution now is to set $rootScope.loading = 1 everytime i call a $http, and on the success set $rootScope.loading = 0.. What is the "best practice" for this? My code now looks like: $rootScope.loading = 1; $http({method : "POST", url:url, data: utils.params(data), headers: {'Content-Type': 'application/x-www-form-urlencoded'}}).success(function() { $rootScope.loading = 0; }); In this case will be better to use interceptor Anytime that we want to provide global

Angular 4 Http POST not working

孤人 提交于 2019-12-04 12:15:35
问题 I hope everyone is doing great. I've recently started working with angular 4.4, i've been trying to post data to my api server, but unfortunately it's not working. I've spent like 2 days on it but still no success. And have already tried 6-7 article even from angular.io. I've tried both Http and Httpclient modules but nothing seems to be working. The problem is, whenever i try to post data to my server, Angular makes http OPTIONS type request instead of POST . this.http.post('http:/

Angular JS cancel $http call before calling a new $http

こ雲淡風輕ζ 提交于 2019-12-04 08:09:37
In angular JS 1.1.5 you can cancel previously started $http calls. These two link1 and link2 gives some explanation on how it works. However I can't understand, how to use this in practice. I created plnkr to illustrate what I want to achieve. User has a link he can click on (as we know, users tend to do that very passionately) If user clicks link, and previous request hasn't yet finished, it should be canceled, and new request should be made (in this example there are other ways to ignore multiple clicks. Original problem is user input field with ng-change on it - request gets made every time

Getting response headers from HttpClient post request in Angular?

不想你离开。 提交于 2019-12-04 04:19:54
问题 I'm trying to get the response headers from a post request, but the HttpResponse object doesn't contain the same headers that I can see in the network. What am I doing wrong? I need to access the value of the Apiproxy-Session-Id key and it isn't present in the HttpHeaders. This is my code to execute the post request and log the full response, where http is an HttpClient object. this.http.post('http://localhost:8081/user/login', JSON.stringify(requestBody), {observe: 'response'}).subscribe

How to catch error in Observable.forkJoin(…)?

僤鯓⒐⒋嵵緔 提交于 2019-12-03 23:21:09
I use Observable.forkJoin() to handle the response after both http calls finishes, but if either one of them returns an error, how can I catch that error? Observable.forkJoin( this.http.post<any[]>(URL, jsonBody1, postJson) .map((res) => res), this.http.post<any[]>(URL, jsonBody2, postJson) .map((res) => res) ) .subscribe(res => this.handleResponse(res)) siva636 You may catch the error in each of your observables that are being passed to forkJoin : // Imports that support chaining of operators in older versions of RxJS import {Observable} from 'rxjs/Observable'; import {forkJoin} from 'rxjs

Display Subscribe Data in Angular 4

烈酒焚心 提交于 2019-12-03 20:28:13
I need help in displaying the output of subscribe from an api in Angular 4. How can i do this since I wrote data.data.data but it says property data doesnt exist on type object. How would i output it in the browser? Here's my code below and the api picture below import { Component, OnInit } from '@angular/core'; import { NewsService } from '../news.service'; @Component({ selector: 'app-news-list', templateUrl: './news-list.component.html', styleUrls: ['./news-list.component.css'] }) export class NewsListComponent implements OnInit { constructor(private newsService: NewsService) { } ngOnInit()

Handling Expired Token From Api in Angular 4

风格不统一 提交于 2019-12-03 17:20:04
问题 I need help in handling expired token in my angular application. My api has the expired time but my problem is when i forgot to log out of my angular application, after some time, i still can access the homepage but without data. Is there something i can do about this? Are there libraries that can handle this? or are there something i could install? Better, if i nothing will be installed. Here's my authentication code below? Can i add anything that can handle expiration and I won't be able to

Angular 2 http post params and body

删除回忆录丶 提交于 2019-12-03 05:51:24
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: this.getAuthorizedHeaders(), responseType: ResponseContentType.Json, params: params, body: data,

AngularJS: Performing $http request inside custom service and returning data

怎甘沉沦 提交于 2019-12-03 03:21:40
问题 I have defined a custom http service in angular that looks like this: angular.module('myApp') .factory('myhttpserv', function ($http) { var url = "http://my.ip.address/" var http = { async: function (webService) { var promise = $http.get(url + webService, { cache: true }).then(function (response) { return response.data; }); return promise; } }; return http; }); And I can access this service in my controller like so: angular.module('myApp') .controller('myCtrl', function (myhttpserv) { var