angular-http

Property 'includes' is missing in type 'Subscription' -angular2

那年仲夏 提交于 2019-12-08 18:28:27
I have been trying to get an array of objects from node to a service onInit and assign it to component. I am able to view data in service but when i try to assign to a variable in component, I get below error. I have included my code as well. Please favour on this.All i need is to just take that array from service and assign it to finallist in component. ERROR in C:/Users/girija/Documents/animapp/src/app/components/list.component.ts (28,5): Type 'Subscription' is not assignable to type 'any[]'. Property 'includes' is missing in type 'Subscription'. My code is below: app.service.ts: public

Set Cookie in Request Headers Angular2

心不动则不痛 提交于 2019-12-08 15:41:37
问题 I am new to angular2. My server(spring) responds authentication with a set-cookie value in its response headers. How to set that cookie to the request headers for the next API calls? I searched a lot, but I cannot find a suitable solution. 回答1: Cookies are automatically attached to every call you make after it i saved for your domain. You are doing something else wrong. In case you want to create automatic mechanism for attaching auth data to REST calls, refere to this tutorial that creates

Angularjs - $http success vs then

佐手、 提交于 2019-12-08 02:34:14
问题 I want to ask about the difference about this method My concern is difference between .then and .success, function and also .error thanks. // Simple GET request example: $http({ method: 'GET', url: '/someUrl' }).then(function successCallback(response) { // this callback will be called asynchronously // when the response is available }, function errorCallback(response) { // called asynchronously if an error occurs // or server returns response with an error status. }); and // Simple GET

Angular 2 Http RetryWhen

此生再无相见时 提交于 2019-12-07 10:58:31
问题 I'm trying to use retryWhen in HTTP calls. It works perfectly when try to use like this: return this.http.get(`${environment.apiUrl}/track/${this.user.instance._id}/${this.currentPlayer.playlist.id}/next?s=${this.playerCounter}`, options) .timeout(500, new TimeoutError(`Timeout trying to get next track. [instanceId=${this.user.instance._id}]`)) .retryWhen(attempts => { return Observable.range(1, 3).zip(attempts, i => i).flatMap(i => 3 === i ? Observable.throw(attempts) : Observable.timer(i *

Angular $http.get to localhost, always returns 404. 200 in browser

一笑奈何 提交于 2019-12-07 04:54:42
问题 I can't create a successful get request in Angular 1.2.13. var getProgress = function() { var promise = $http({method: 'GET', url: 'http://localhost:8080/project/local/some/getStatus'}); promise.then(function(success) { alert(JSON.stringify(success)); }, function(error) { alert(JSON.stringify(error)); }, function(notify) { alert(JSON.stringify(notify)); }); }; So I'm trying to receive some JSON from my REST web service. To test the service, I access it from the browsers(IE9,Firefox 27, Chrome

Change detection not registering data changes

走远了吗. 提交于 2019-12-07 01:55:11
问题 I have an html structure with a component inside a component (forgot the proper word for it). working basicly like this (largely simplified): main html: <div *ngFor="let item of data"> <app-item [item]="item"></app-item> </div> <button (click)="addItem()">Add</button> item html: <div>{{item.name}}</div> <button (click)="deleteItem()">Delete</button> inside the app-item I display several items out of a list. The list gets it's data straight out of the database via an http.get request. Now I

Overload request headers and params with HttpClient get

大憨熊 提交于 2019-12-06 06:29:32
In HttpClientModule, is there a method to pass headers and params to get request. import { HttpHeaders, HttpParams, HttpClient } from @angular/common/http'; const headers = { headers: new HttpHeaders({}) } let params = new HttpParams({ }); get(url, {params}) // http client get with params get(url, {headers}); //http client get with headers I want something like requestoptions to hold both or a syntax to do httpClient get sending request headers and params. Currently building complete url with search params and sending headers along. Here is something that passes both headers and parameters in

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

谁说我不能喝 提交于 2019-12-06 03:47:02
问题 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

$http POST response from service to controller

帅比萌擦擦* 提交于 2019-12-06 00:29:08
问题 How to get the response from Service in below case?? Service: app.factory('ajaxService', function($http) { updateTodoDetail: function(postDetail){ $http({ method: "POST", headers: {'Content-Type': 'application/x-www-form-urlencoded'}, url: post_url, data: $.param({detail: postDetail}) }) .success(function(response){ //return response; }); } }) Controller: updated_details = 'xyz'; ajaxService.updateTodoDetail(updated_details); In th above case, i POST the data through Controller and it was

Angular 2 Http RetryWhen

空扰寡人 提交于 2019-12-05 15:26:43
I'm trying to use retryWhen in HTTP calls. It works perfectly when try to use like this: return this.http.get(`${environment.apiUrl}/track/${this.user.instance._id}/${this.currentPlayer.playlist.id}/next?s=${this.playerCounter}`, options) .timeout(500, new TimeoutError(`Timeout trying to get next track. [instanceId=${this.user.instance._id}]`)) .retryWhen(attempts => { return Observable.range(1, 3).zip(attempts, i => i).flatMap(i => 3 === i ? Observable.throw(attempts) : Observable.timer(i * 1000)); }) It makes a maximum of 3 tries if get a Timeout error. But, always have a buuut, I want to