rxjs

typescript error Expected 0 type arguments for get call

六眼飞鱼酱① 提交于 2020-01-04 09:19:07
问题 I am getting typescript error Expected 0 type arguments, but got 1 for line that returns get call. What is wrong with my get call? public get(params: SummaryParams): Observable<Summary[]> { const uri = `${this.config.URLS.LOAD_SUMMARY}`; const params = new HttpParams() .set('startDate', params.startDate.toString()) .set('endDate', params.endDate.toString()) .set('userId', params.userId); return this.http.get<Summary[]>(uri, { params }); } 回答1: HttpClient has generic methods that can be used

How to stop rxjs timer

筅森魡賤 提交于 2020-01-04 06:30:22
问题 I have the following timer: setCountDown() { let counter = 5; let tick = 1000; this.countDown = timer(0, tick) .pipe( take(counter), map(() => --counter), finalize(() => { if (this.currentQuestionNumber < this.questionsToAsk) this.showNextQuestion(); else { this.endQuiz(); } }) ); } How can I stop the timer? E.g. when a user clicks on a button... 回答1: assuming you are using angular, if you use javascript only you can just us fromEvent() to create userClick userClick=new Subject() click()

How to stop rxjs timer

偶尔善良 提交于 2020-01-04 06:30:09
问题 I have the following timer: setCountDown() { let counter = 5; let tick = 1000; this.countDown = timer(0, tick) .pipe( take(counter), map(() => --counter), finalize(() => { if (this.currentQuestionNumber < this.questionsToAsk) this.showNextQuestion(); else { this.endQuiz(); } }) ); } How can I stop the timer? E.g. when a user clicks on a button... 回答1: assuming you are using angular, if you use javascript only you can just us fromEvent() to create userClick userClick=new Subject() click()

Angular HTTP call subscribed to a subject closing the subject

不想你离开。 提交于 2020-01-04 06:26:18
问题 I have two services that can fetch a given object : an initial HTTP call to get the full list, and websocket notification to have live update of new elements. I want to wire the two calls to the same observable so the display page has no knowledge of the backend. There is the call mades : private getInitialData(subject: Subject<any>) { this._http.get<Array<any[]>>(`/call/to/backend`) .flatMap(items => items) .subscribe(subject); } private listenNewData(subject: Subject<any>) { this

Call Async functions (Retunes Observable) from HTML template

北城以北 提交于 2020-01-04 06:06:11
问题 Data displayed on HTML template is Key form data. Meaning, it needs to be translated. For that purpose, I would like to call an Async function from my template. Tried this, with no success: Template: <span class="myClass-rowValue">{{translateServingStyle(size.defaultServingStyle?.surcharge) | async}}</span> Component ts file: servingStylesData$: Observable<ServingStyles_servingStyles[]>; ngOnInit(): void { this.servingStylesData$ = of(this._apollo .watchQuery<ServingStyles>({ query:

Multicast Operator with Pipe in RxJS 5.5+

心不动则不痛 提交于 2020-01-04 05:54:49
问题 How do I use the multicast() operator with the new recommended approach in RxJS 5.5 of using pipe() instead of chaining operators? I get a TypeScript error when I try to use connect() like I did before: const even$ = new Subject(); const connectedSub = interval(500) .pipe( filter(count => count % 2 === 0), take(5), multicast(even$) ) .connect(); even$.subscribe(value => console.log(value)); This code works but yields a TypeScript error that reports that Property 'connect' does not exist on

Other operator in calculation chain than combineLatest to avoid redundant calculations

自古美人都是妖i 提交于 2020-01-04 05:21:22
问题 I've successfully migrated a larger Excel calculation to JS using RxJS. Any input data is represented as an Observable and subsequent calculations are implemented with .map and .combineLatest when any Excel formula uses more than one input. This works great except for one problem. Here is a simplified example: Three inputs ( a$=1 , b$=2 , c$=3 ) are used in two different calculations ( $ab = $a+$b = 3 in the first, $bc = $b+$c = 5 in the second) as intermediate steps to calculate the final

RxJS Observable.concat: How to know where next result came from?

核能气质少年 提交于 2020-01-04 05:10:26
问题 My application (Angular 2 with RxJS 5 written in TypeScript) requires me to make 2 calls to a web service in a predefined order. Inspired by this page I decided to try the concat operator of RxJS observables. The twist is that the onNext callback that receives values needs to forward them to different handlers depending on where they came from My code can be simplified to: suscription1 = Observable.return({name:'John', age:7}); subscription2 = Observable.return({name:'Mary', color:'blue'});

RXJS draw line on html5 canvas

丶灬走出姿态 提交于 2020-01-04 05:05:45
问题 I'm trying to achieve the same effect I'm posting here using Reactive Extensions for Javascript (RX-JS). I'm a bit puzzled on how to do it. Here is the page: <!DOCTYPE html> <html> <head> <title>drag and drop</title> </head> <style type="text/css"> canvas { border:1px solid steelblue; background-color: whitesmoke; } </style> <body> <canvas id="canvas" width=300 height=300></canvas> <script type="text/javascript" src="http://code.jquery.com/jquery-1.11.0.min.js"></script> <script type="text

RxJS observe an object

泄露秘密 提交于 2020-01-04 04:31:24
问题 I am new to RxJS so I apologize for the newbie question. I have a local javascript object defined as: model.user = { firstName: 'John', lastName: 'Smith' } I am binding each property to an input control where the user can change the values. I would like to be able to observe this object and capture the event when the value of any of the properties change. Is this achievable with RxJS? Thanks. 回答1: Instead of using an object, you can store your entire state as Observable. Here is the example