rxjs

rxjs observable angular 2 on localstorage change

家住魔仙堡 提交于 2019-12-18 10:44:34
问题 I am trying to create an observable that returns values when changes to a localStorage variable happens. My subscriber is not getting the new values upon changes to localStorage (or for that matter an in memory variable). navbar.component.js import { Component, OnInit } from '@angular/core'; import { UserService } from '../services/user.service'; /** * This class represents the navigation bar component. */ @Component({ moduleId: module.id, selector: 'sd-navbar', templateUrl: 'navbar.component

node_modules/rxjs/internal/types.d.ts(81,44): error TS1005: ';' expected error after installation of Angular 6

こ雲淡風輕ζ 提交于 2019-12-18 09:59:31
问题 I got an error of node_modules/rxjs/internal/types.d.ts(81,44): error TS1005: ';' expected. after the installation of Angular 6. Check the error: ERROR in node_modules/rxjs/internal/types.d.ts(81,44): error TS1005: ';' expected. node_modules/rxjs/internal/types.d.ts(81,74): error TS1005: ';' expected. node_modules/rxjs/internal/types.d.ts(81,77): error TS1109: Expression expected. 回答1: This problem might arise due to version mismatch. To solve your problem you need to do following changes in

how to build single object from 2 http requests in angular, without adding another value

感情迁移 提交于 2019-12-18 09:39:29
问题 If you look at this question. the problem was really simple, but solutions were more complicated, to address more details I am asking this question. If you look at stackblitz in service the code tries to build an object before passing it to a component. The problem I am having is the key value that is added by the code and it is breaking the formcontrols. the first response returns object with routes that have only these values. addressPointId: "adress", municipalityId: "municipallyty",

Angular2 2.0.x and Rx 5 beta.12 bundle

别等时光非礼了梦想. 提交于 2019-12-18 09:34:18
问题 I am currently updating the dependencies of my project which uses the Angular2 npm packages and therefore RxJs as well. I am updating to the 2.0.2 stable release of angular which depends on Rx5 beta.12. For my web application i only deploy the Rx.min.js bundle and load it with a script tag in my index.html file. That approach worked perfectly before with the Rx umd bundle, but causes errors meanwhile, since it appears to me that the contributors of RxJs dropped the different bundle versions

Observable Undefined

旧巷老猫 提交于 2019-12-18 07:15:21
问题 I'm trying to extract the values from an observable, my subscription (component) code is as followed: this.checkoutService.getDisabledDate().subscribe (dates=>{this.formattedDate=dates}, (error:any)=>{console.log(error)}); In the 'dates' callback a console.log of this.formattedDate prints the correct values. However trying to access this.formattedDate outside of the subscription is undefined. the service code: getDisabledDate():Observable<any>{ let headers = new Headers({'Content-Type':

How to create an http observable that makes dynamic requests

末鹿安然 提交于 2019-12-18 07:09:22
问题 I have an observable that makes dynamic requests. For example, getFlowers(params?: any): Obeservable<Flower[]> { return this.http.get<Flower[]>( `http://flowers.com/flowers`, { params } ) } Now, the above function returns new http observable each function call. I would like to somehow achieve returning the same observable instance (despite making different http calls) such that I can use switchMap to cancel previous simultaneous requests. I have an idea that I should create an Observable

Why is jest.useFakeTimers not working with RxJs Observable delay

不羁的心 提交于 2019-12-18 07:03:04
问题 I'm wondering why jest.useFakeTimers is working with setTimeout but not with the delay operator of RxJs: jest.useFakeTimers(); import {Observable} from 'rxjs/Observable'; import 'rxjs'; describe('timers', () => { it('should resolve setTimeout synchronously', () => { const spy = jest.fn(); setTimeout(spy, 20); expect(spy).not.toHaveBeenCalled(); jest.runTimersToTime(20); expect(spy).toHaveBeenCalledTimes(1); }); it('should resolve setInterval synchronously', () => { const spy = jest.fn();

Angular/rxjs: Why don't I have to import toPromise anymore? [closed]

纵饮孤独 提交于 2019-12-18 06:49:15
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago . A ton of SO answers say that to avoid problems like Property 'toPromise' does not exist on type 'Observable' in Angular, you have to import 'rxjs/add/operator/toPromise' which I've done until recently. In an Angular 4.2.4 project, I forgot the import and expected to see an error.

Angular/rxjs: Why don't I have to import toPromise anymore? [closed]

二次信任 提交于 2019-12-18 06:49:06
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago . A ton of SO answers say that to avoid problems like Property 'toPromise' does not exist on type 'Observable' in Angular, you have to import 'rxjs/add/operator/toPromise' which I've done until recently. In an Angular 4.2.4 project, I forgot the import and expected to see an error.

RxJS: How can I do an “if” with Observables?

情到浓时终转凉″ 提交于 2019-12-18 04:57:10
问题 Say I have two observables and one I want to listen on changes in one observable, if the other on matches a certain condition. I tried it with zip but it seems I will only be notified, if both observables change, but I want to be notified for every change on the one observable, if the condition of the other one is true. What I tried: var firstState = new Rx.BehaviorSubject(undefined); var secondState = new Rx.BehaviorSubject(undefined); Rx.Observable.zip(firstState, secondState, function