rxjs5

angular 2 http post not working

China☆狼群 提交于 2020-06-29 12:09:06
问题 Here's my code: const dummydata = { param1: 72766, param2: 'ELS' } var foo = JSON.stringify(dummydata) let headers = new Headers(); headers.append('content-type', 'application/json'); this.http.post(url, foo, { headers: headers }).map(res => res.json()).subscribe( () => { alert('Success'); } ); For some reason there's no data going to the server as form-data in Request Payload and the type is getting converted to OPTIONS instead of POST On the other hand if I remove, headers , then the form

angular 2 http post not working

故事扮演 提交于 2020-06-29 12:07:30
问题 Here's my code: const dummydata = { param1: 72766, param2: 'ELS' } var foo = JSON.stringify(dummydata) let headers = new Headers(); headers.append('content-type', 'application/json'); this.http.post(url, foo, { headers: headers }).map(res => res.json()).subscribe( () => { alert('Success'); } ); For some reason there's no data going to the server as form-data in Request Payload and the type is getting converted to OPTIONS instead of POST On the other hand if I remove, headers , then the form

Async Pipe in Template inside ngFor block triggers http GET calls loop

断了今生、忘了曾经 提交于 2020-06-27 10:13:33
问题 I have the following component Template: <div *ngFor="let ctrl of data; trackBy:ctrl?.Id"> <div *ngIf="getNext(ctrl.nextDate) | async as next"> <span>{{next | date: 'dd.MM.yyyy'}}</span> </div> </div> getNext() is a simple method returning an Observable<Date> : public getNext(deadline: string): Observable<Date> { return this.http.get<Date>(`${this.config.apiEndpoint}/api/meeting?deadline=${deadline}`); } My goal would be to invoke the method and subscribe to the observable with the async pipe

What is observable, observer and subscribe in angular?

穿精又带淫゛_ 提交于 2020-05-22 21:21:50
问题 I am learning angular and i got confuse in these observable, observer and subscribe thing. So please explain. 回答1: Here is a simple visual to see the difference: As seen above ... an Observable is a stream of events or data. They are often returned from Angular methods, such as the http.get and the myinputBox.valueChanges . Subscribing "kicks off" the observable stream. Without a subscribe (or an async pipe) the stream won't start emitting values. It's similar to subscribing to a newspaper or

What is observable, observer and subscribe in angular?

天涯浪子 提交于 2020-05-22 21:14:47
问题 I am learning angular and i got confuse in these observable, observer and subscribe thing. So please explain. 回答1: Here is a simple visual to see the difference: As seen above ... an Observable is a stream of events or data. They are often returned from Angular methods, such as the http.get and the myinputBox.valueChanges . Subscribing "kicks off" the observable stream. Without a subscribe (or an async pipe) the stream won't start emitting values. It's similar to subscribing to a newspaper or

RX.JS Redux Observable Multiple Get requests at same time

蓝咒 提交于 2020-05-15 10:19:10
问题 I am trying to set up an observable that currently receives an array of location IDs and then makes a get request for all of these at once and waits for the response for them all. Here is a sample: const fetchPhotosEpic = action$ => action$.ofType(LOCATIONS_RECEIVED) .map(action => action.payload) .mergeMap((data) => { let promiseArray = data.map(location => Observable.fromPromise(axios.get(photosUrl(location.id)))) return Observable.forkJoin( promiseArray ) }) .map(responses => responses.map

Can't make debounceTime() or throttleTime() to work on an Angular http request

倾然丶 夕夏残阳落幕 提交于 2020-04-10 09:10:59
问题 For the life of me, I can not make this work. I've searched and searched, but I couldn't find any example (all examples out there are with .fromEvent() , none on a http.get ). In my template, I have this input: <input type="text" (input)="categoriesSearch($event)"> In my component, I have the following: categoriesSearch(event) { this.categoriesSubscription = this.apiService .getCategoriesList(this.uploadForm.get('categories').value) .debounceTime(3000) // .throttleTime(3000) .subscribe(

Can't make debounceTime() or throttleTime() to work on an Angular http request

半城伤御伤魂 提交于 2020-04-10 09:09:02
问题 For the life of me, I can not make this work. I've searched and searched, but I couldn't find any example (all examples out there are with .fromEvent() , none on a http.get ). In my template, I have this input: <input type="text" (input)="categoriesSearch($event)"> In my component, I have the following: categoriesSearch(event) { this.categoriesSubscription = this.apiService .getCategoriesList(this.uploadForm.get('categories').value) .debounceTime(3000) // .throttleTime(3000) .subscribe(

Observable.forkJoin() TS2322 error after updating to TypeScript 2.4.1 and Rxjs 5.4.2

给你一囗甜甜゛ 提交于 2020-01-24 14:14:25
问题 In our angular 4.2.4 application, we use RxJS's Observable.forkJoin in a number of places to return heterogeneous types. For example: private fleet: Aircraft[]; private contractList: string[]; Observable.forkJoin([ this.fleetService.getFleet(), this.fleetService.getContractList() ]).subscribe( next => { this.fleet = results[0]; this.contractList = results[1]; }, error => console.error ); with the following service signatures: getFleet(): Observable<Aircraft[]> { ... } getContractList():

Convert infinite async callback sequence to Observable sequence?

大城市里の小女人 提交于 2020-01-23 07:51:21
问题 Let's say I have the following asynchronous callback-based "infinite" sequence, which I cancel after some time: 'use strict'; const timers = require('timers'); let cancelled = false; function asyncOperation(callback) { const delayMsec = Math.floor(Math.random() * 10000) + 1; console.log(`Taking ${delayMsec}msec to process...`); timers.setTimeout(callback, delayMsec, null, delayMsec); } function cancellableSequence(callback) { asyncOperation((error, processTime) => { console.log('Did stuff');