observable

How to return string instead of Observable with @angular/http

本秂侑毒 提交于 2020-01-14 19:02:09
问题 I am hooking Angular 4 with .net core WEB API. The Web API is returning a CustomerName in string based on the Id passed in. This is the service method in Angular 4. I understand that angular/http must return an Observable because it is an Async call. But how do I return a string instead? or how do I access the data within the Observable object from the calling method? getCustomerName(id: number): Observable<any>{ return this._http.get(this.baseUrl + 'api/getCustomerName/' + id ) .map(

Angular 6 - rxjs pipe not working on valueChanges

半腔热情 提交于 2020-01-14 10:33:17
问题 I have a reactive form, with a text input. For ease of access in my typescript, I declared: get parentId(): FormControl { return this.addForm.get("parentId") as FormControl; } This part works, the control is properly accessed. Now in my ngOnInit if I do this: this.parentId.valueChanges.subscribe(() => console.log("Changed")); The console log is executed at every character changed in the input, as expected. But if I do this: this.parentId.valueChanges.pipe(tap(() => console.log("Changed")));

How do I return the response from an Observable/http/async call in angular?

浪子不回头ぞ 提交于 2020-01-14 06:47:23
问题 I have service which returns an observable which does an http request to my server and gets the data. I want to use this data but I always end up getting undefined . What's the problem? Service : @Injectable() export class EventService { constructor(private http: Http) { } getEventList(): Observable<any>{ let headers = new Headers({ 'Content-Type': 'application/json' }); let options = new RequestOptions({ headers: headers }); return this.http.get("http://localhost:9999/events/get", options)

Passing through multiple parameters to rxjs operator

雨燕双飞 提交于 2020-01-13 08:32:09
问题 Is there a more elegant way of doing the following? private getHeaders(): Observable<any> { let version; let token; return this.appInfo.getVersion() .pipe( tap(appVersion => version = appVersion), mergeMap(() => this.storage.get('access_token')), tap(accessToken => token = accessToken), mergeMap(accessToken => of(this.createHeaders(version, token))) ); } How can I more fluently remember the two return values of this.appInfo.getVersion() and this.storage.get('access_token') without writing

Load route after data is set in Angular 4

佐手、 提交于 2020-01-13 06:56:06
问题 In my application, I have some data that is common throughout the application. But the data is populated after the view loads. For example data such as user-settings, profile etc. I know we can use resolve for loading data before the view loads, but I cant add resolve to all the routes. So when a specific route is refreshed the data is not available or the response from the server comes after the view loads. How can this be done? Below is the sample code of what I'm trying to achieve. in App

Angular2 - Load binary image data asynchronously inside ngFor

天涯浪子 提交于 2020-01-13 06:31:36
问题 I'm trying to load some images using node's fs module. I have it working on a single image but what is the correct way to do this inside an ngFor loop? Currently I have: <div *ngFor="let job of getJobs() | async"> <img src={{readImageFile(job.thumbUrl)}}> </div> getJobs() returns an observable from my service. readImageFile() calls a Meteor server-side method which loads the image data using fs and returns it asynchronously: readImageFile(url) { if (url) { this.call('readImageFile', url,

Angular2 - Load binary image data asynchronously inside ngFor

狂风中的少年 提交于 2020-01-13 06:31:07
问题 I'm trying to load some images using node's fs module. I have it working on a single image but what is the correct way to do this inside an ngFor loop? Currently I have: <div *ngFor="let job of getJobs() | async"> <img src={{readImageFile(job.thumbUrl)}}> </div> getJobs() returns an observable from my service. readImageFile() calls a Meteor server-side method which loads the image data using fs and returns it asynchronously: readImageFile(url) { if (url) { this.call('readImageFile', url,

Angular 6 + RxJS 6.0 : How to push new element to array contained by Observable

怎甘沉沦 提交于 2020-01-12 07:28:08
问题 I am receiving data from firebase server in chunks while rendering that data requires a library which insists on observable contains Array. I am somehow unable to push a new data chunk to existing data chunk array contained by observable, From dataservice I am calling by subject's next and trying to add a new calEvent this.homeWorkerService.eventSubject.next(calEvent); In component, I have following code events$: Observable<Array<CalendarEvent<any>>>; and ngOnInit, I am supplying data to it

Error: Property timer doesn't exist on type typeof Observable

廉价感情. 提交于 2020-01-12 05:25:07
问题 The code is below import {Component} from 'angular2/core'; import {Observable} from 'rxjs/Rx'; @Component({ selector: 'my-app', template: 'Ticks (every second) : {{ticks}}' }) export class AppComponent { ticks =0; click(){ let timer = Observable.timer(2000,1000); timer.subscribe(t=>this.ticks = t); } } But i am getting an error. The error is in the following line: let timer = Observable.timer(2000,1000); The definition of error is "property timer doesn't exist on type typeof Observable" Why

How to transform a nested list of double values into a Java class using RxJava?

眉间皱痕 提交于 2020-01-11 12:23:14
问题 In my Android client I receive this JSON data from a backend: [ [ 1427378400000, 553 ], [ 1427382000000, 553 ] ] Here is the routine which actually loads the data. I am using RxAndroid and Retrofit here. private void getProductLevels() { Observable<List<List<Double>>> responseObservable = mProductService.readProductLevels(); AppObservable.bindFragment(this, responseObservable) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) // TODO: Transform List<List<Double>> into