observable

RXJS: Single Observable from dynamically created Observables

南笙酒味 提交于 2019-12-12 04:27:52
问题 I am trying to create an observable (fixedObservable here) which will be fed by multiple dynamically created observable over time. Whenever a subscription is made than the subscriber should get the most recent value from the fixedObservable. Although I have achieved it but I wanted to know if there is any simple solution to it. You can find the code here https://jsfiddle.net/dzm2t3pa/8/ . Thanks var resultdiv = document.getElementById('result'); function print(message) { var paraEl = document

Angluar2 Observable UI - Update Children in Object Array force Change?

限于喜欢 提交于 2019-12-12 03:28:53
问题 Let's say I have a simple array object like so: validationMessages = { 'name': [{ 'type': 'required', 'message': 'Name is required.', 'enabled': 1 }, { 'type': 'maxlength', 'message': 'Name cannot be more than 50 characters long.', 'enabled': 0 }], 'description': [ { 'type': 'required', 'message': 'Description is required.', 'enabled': 0 }, ] }; I'm then displaying on load in my UI like so: <div *ngFor="let err of validationMessages.name"> <div *ngIf="err.enabled == 1" class="alert alert

Is it possible to update Observable with own data in Angular2 / Typescript?

岁酱吖の 提交于 2019-12-12 02:46:46
问题 I have an ngFor with async like that: <div *ngFor="let location of googleSearchLocations | async"> <div *ngFor="let location of facebookSearchLocations | async"> and this is my component: private searchTerms = new Subject<string>(); googleSearchLocations: Observable<GoogleLocation[]>; facebookSearchLocations: Observable<FacebookLocation[]>; ngOnInit(): void { this.googleSearchLocations = this.searchTerms .debounceTime(300) .switchMap(term => term ? this.locationService.getGoogleLocations(term

Observable - converting 2 promises into an observable

徘徊边缘 提交于 2019-12-12 02:39:17
问题 I have a popular scenario where I need to create one promise that returns data which is fed to a second promise. If the first promise fails, I need to cancel the second promise. In 'Promise' land it would look something like this: Fn1.doPromise( initialData ) .then(info => { Fn2.doPromise( info ) .then(result => { //success - return result }) .catch(error => { //error }); }) .catch(error => { //cancel 2nd promise and show error }); Now I am trying to learn the best way to do this using

RxJs Observable interval until reached desired value

戏子无情 提交于 2019-12-12 02:30:36
问题 I want to poll for changes and when a desired value is reached the Observable should complete (or wait until timeout). Right now I use the filter which works fine to wait until the desired value is reached. But I want the Observable to push events while waiting for this value. For example, I wait for the status 'success' and until the status changes to 'success' the status 'testing' is returned from my service. But since the filter is waiting for 'success', 'testing' never returns. My code

Rx Subscribe OnComplete fires but cannot use the data

北城以北 提交于 2019-12-12 02:12:45
问题 I have a product service with a method that returns an Observable from json data. product.service.ts.... getProducts(): Observable<IProductData[]> { return this._http.get(this._productUrl) .map((response: Response) => <IProductData[]> response.json()) .catch(this.handleError); } In my component I subscribe to the serivce and call the getProducts() method returning the Observable IProductData[]. mycomponent.ts .. productData: IProductData[]; ngOnInit(): void { this._productService

Angular2 - return observable of object created in map function

删除回忆录丶 提交于 2019-12-12 02:11:02
问题 Say I have this function... public getStuff(): Observable<Stuff> { return.http.get('url') .map(res => res.json()) .map((data: Piece) => { var stuff = new Stuff(); // Apply logic to "data", modify stuff model, return stuff to subscriber }); } How do I return the stuff object to the observer instead of the "data" of type Piece? 回答1: If you use a code block you need an explicit return : public getStuff(): Observable<Stuff> { return.http.get('url') .map(res => res.json()) .map((data: Piece) => {

Angular 2 Http post error

混江龙づ霸主 提交于 2019-12-11 23:27:55
问题 I have an Ionic 2 app that will get some events from Facebook. I'm trying to send a post request to the Graph Api with a batch containing multiple requests but my subscription always return this error: {"_body":"","status":404,"statusText":"Ok","headers":{"Client-Via", ["shouldInterceptRequest"]},"type":2,"url":"https://graph.facebook.com/"} The subscription inside my component: this.eventListService.get() .subscribe( response => this.response = response, error => this.error = error )

ViewDestroyedError: Attempt to use a destroyed view

折月煮酒 提交于 2019-12-11 23:09:57
问题 (angular 8 in use) I have an issue currently with my code using a behaviour subject. Component A creates another component B trough the component factory. Now, Component A subscribes to component B it's status to know when to delete it. In this case, whenever there is an error in component B, Component A will change its own status and call Component B.destroy(). However, whenever I will run this destory method, I get an error in the logs saying ERROR Error: ViewDestroyedError: Attempt to use

Angular: Should I subscribe() to http.get() each time I need to update?

非 Y 不嫁゛ 提交于 2019-12-11 19:06:29
问题 I wonder if I am using Observable.subscribe() too many times or not. In my component class, I have a function loadData(). It calls another function this.service.getData() that uses HttpClient.get() to perform a HTTP request to the server. Currently in my function loadData(), I subscribe to the result of this.service.getData(). Each time the user clicks on a "Update" button, I would like to call my function loadData(). The question If I call my function loadData() every time I need to perform