angular2-observables

Angular2 : Chain http requests with concat()

让人想犯罪 __ 提交于 2020-01-15 08:45:08
问题 I have some difficulties to chain several HTTP requests. First, the request is defined in this service method that returns a cold Observable. FormPartService submitFormPart(id: string, part: string, data: any) { let body = JSON.stringify({ claimFileId: claimFileId, part: part, data: data }); return this.http.post('/form-part', body) .map( (res) => { let body = res.json(); if (body.data){ return body.data; } } ); } I have a variable number of form part to submit depending if they are dirty or

Angular 2 *ngFor and form submit ceased working when moved to observables

安稳与你 提交于 2020-01-06 19:47:07
问题 I had an app initiating course components like this: <li *ngFor="let course of courses"> <app-course [appCourse]="course" (remove)="removeItem($event)" ></app-course> </li> from an array pulled from local storage, which was populated from a course form, sending an object like this: { "_id": "587f52ad266c32fbfb10f21a", "end": "31/1/2017", "start": "1/1/2017", "desc": "see title", "name": "Intro To Express", "id": 1, "__v": 0, "updated_at": "2017-01-18T11:34:05.416Z" } Then I added a back end

angular2 - cannot get data from web service

可紊 提交于 2020-01-06 19:39:28
问题 Learning typescript & angular2 for the first time. I'm creating a generic service that just does GET and POST so that I can use it in the entire app. I've based my app on Angular's example from Dynamic Forms My issue is that my "QuestionService" is using a "ServerService" but it is complaining that this.ServerService.getData is not a function isnt a function. ServerService import { Injectable } from '@angular/core'; import { Http, Response } from '@angular/http'; import { Observable } from

angular2 - cannot get data from web service

元气小坏坏 提交于 2020-01-06 19:39:02
问题 Learning typescript & angular2 for the first time. I'm creating a generic service that just does GET and POST so that I can use it in the entire app. I've based my app on Angular's example from Dynamic Forms My issue is that my "QuestionService" is using a "ServerService" but it is complaining that this.ServerService.getData is not a function isnt a function. ServerService import { Injectable } from '@angular/core'; import { Http, Response } from '@angular/http'; import { Observable } from

Angular2. How can I check if an observable is completed?

旧时模样 提交于 2019-12-29 05:06:05
问题 In my page there is a button that generates a report. That report needs data that is loaded using a http call to a rest endpoint when the page is loaded, but I do not have a guarantee that they are loaded when the user presses the report button. How can I watch the observable to see if it is completed, and if incomplete, to wait on the action until the http call is completed? Here is some of the code: loadCompanies(): void { this._companyService.getCompanies().subscribe( response => { this

Best way to import Observable from rxjs

蓝咒 提交于 2019-12-28 01:42:23
问题 In my angular 2 app I have a service that uses the Observable class from the rxjs library. import { Observable } from 'rxjs'; At the moment I am just using Observable so that I can use the toPromise() function. I read in another StackOverflow question somewhere that importing in this way and also importing from rxjs/Rx will import a whole lot of unnecessary stuff from the rxjs library that will increase the page load times and/or the code base. My question is, what is the best way to import

ag-grid does not refresh when using Observables

允我心安 提交于 2019-12-25 09:26:43
问题 I'm trying to bind the Angular-2 ag-grid with an Observable. The data in the grid is shown as expected when the grid loads for the first time. Following is the code that does this: this.settingsService.gen.subscribe( (settings) => { this.gridOptions.rowData = settings; }); I have set the grid options in the constructor of the typescript class in the component. Now, when I update the data for the observable, I see the updated changes propagated to the 'settings' (shown above), but the grid

angular2 router become undefined in subscribe method

倾然丶 夕夏残阳落幕 提交于 2019-12-25 07:41:13
问题 As the title explains it, the router object become undefined when it's called inside a subscribe member. Let me show you some code: export class AuthComponent implements OnInit { password = ''; email = ''; constructor( private _router: Router, private authService: AuthService ) { } sendLogin(): void { this.authService.login(this.email, this.password) .subscribe(function(token){ console.log("Success Response" + token) this.token = token // TOKEN Here is good // now I want to change my page,

Use of <ClassName[]> syntax

血红的双手。 提交于 2019-12-24 10:47:21
问题 I'm currently working on a basic chat app using Ionic 2 and have come across this syntax a few times: private someFunction(): Observable<ClassName[]> { I have been looking to understand what the <ClassName[]> is doing but am not sure if this is something specific to Ionic 2, Angular 2 or Typescript. I have searched docs of each but am yet to find any reference to this. 回答1: As it's been told in the comments, it is a Typescript syntax aspect, but also on your case you're using RxJS Observable

Angular Observable chaining

回眸只為那壹抹淺笑 提交于 2019-12-24 08:47:36
问题 What i have done is: A B C D E F ---------------------- 2 4 6 2 5 7 3 3 6 0 6 8 3 6 5 1 6 8 5 0 1 1 1 5 1 2 2 0 1 5 WHY I AM Subscribing B to A , C-> B , because on change of A , B will change and on change of B -> C will change (its like excel) where there are formulas on each field and change of each field other field will change ObservableB[i] = ObervableA[i]; ObservableC[i] = ObservableB[i].pipe(); ObservableD[i] = obbservableC[i].pipe( Map(res => res +1) ); ObservableE[i] = ObservableD[i