rxjs

Get array element in observable at particular index [html]

别来无恙 提交于 2019-12-12 06:50:46
问题 How does one go about getting a single value from an Observable that contains an array using html. Im running Angular2 w/Typescript typescript private observable = Observable.of([1,2,3,4,5]) html <p>{{observable[2]}}</p> i.e get the array element in index 2 held by the observable 回答1: According to previous answers. You should avoid 2 things (if possible): Manual .subscribe() . Use async pipe instead so it will manage subscription for you. Internal state like .subscribe(val => this.val = val)

merge two observables array into single observable array

时光怂恿深爱的人放手 提交于 2019-12-12 06:39:06
问题 I have a Observable array similarIdeasObservable$ and another Observable array being getting from server by like this.ideaService.getSimilarIdeas() . I want to merge these two Observable arrays without using subscribe. How Can I do this? I am trying following way this.similarIdeasObservable$.pipe(concat(this.ideaService.getSimilarIdeas(this.idea).pipe( concatMap(i => i), toArray(), catchError(error => { throw error; }), finalize(() => { this.loading = false; }) ))); concat is deprecated. 回答1:

Circular Dependencies with RxJS. Modeling spores

僤鯓⒐⒋嵵緔 提交于 2019-12-12 06:06:48
问题 I try to model some game with RxJS. but I found some troubles with circular dependencies. So, I simplified my game to a simple simulation(I left only 'move' action). You can find code below(I omitted some parts, you can find the repo here) const rx = require('rx') const math = require('mathjs') const _ = require('underscore') const FIELD_SIZE = 10 const ctx = require('axel'); let getInitialState = () => { return { size: FIELD_SIZE, people: [ { x: 0, y: 0 }, { x: 9, y: 9 }, { x: 5, y: 5 } ] }

SystemJs Ignores Angular Dependency Bundle

谁说我不能喝 提交于 2019-12-12 05:59:29
问题 I am trying to get my angular application to the point where it is ready for distribution and I have managed to create 2 bundles, one for my angular application and one for my dependencies ( which include the angular framework and the rxjs framework ). I am using systemjs builder to do the bundling and using gulp to run the builder. Both bundles are produced and my custom bundle (which contains my code) is loaded by the front end but the vendor/dependency bundle is ignored and the

chained Rx calls called multiple times

南楼画角 提交于 2019-12-12 05:36:45
问题 I need to execute http get calls sequentially. This How to chain Http calls in Angular2 has a very good explanation of how to do that. However whenever I revisit the route my observables are called 2 times more after every visit. So many repeat http calls is not good. How do I make sure that calls are made only once. unsubscribing on destroy does not seem to help either. ngOnInit() { let counter1 = 0, counter2 = 0; console.log('MyBiraComponent ngOnInit'); let uk = this.us.get(); this.u = uk

Can't use concatMap() with angular2 Http

耗尽温柔 提交于 2019-12-12 05:12:36
问题 I need to chain many http requests, the number of request is variable and they are not dependant from the result of the previous one, I just need to keep the returned object of the last request. I've been given two solutions on this thread, the first solution using Observable.concat() works, but a contributor suggested me a more elegant way to perform that, by using concatMap() . Here's my current code : MyComponent submitForms() { var formToSubmit = [...]; // Contains dirty forms that be

BehaviorSubject gives error for next function when i try to add the variable using next().“ I get the error this.count.next is not a function”

无人久伴 提交于 2019-12-12 04:47:51
问题 Inside Angular service i have a variable count, which i want to observe whenever it's updated, i want to set that updated value to another variable in a different component. import {BehaviorSubject} from "rxjs/BehaviorSubject"; import 'rxjs/Rx'; export class DashboardService{ count = new BehaviorSubject<number>(0); count$=this.count.asObservable(); addCount(data){ this.count.next(data); } } I get the error eventhough i have imported all the relevant libraries .Any idea why i'm getting this?

RXJS chain observables completing at any point

这一生的挚爱 提交于 2019-12-12 04:46:33
问题 Is there any way to chain several observables but allowing the chain to complete at any time? I have three Observables, they all return booleans. However, I would only want to progress to the next observable in the chain if the current observable is false. The observables must progress upon the completion of the last one and where the completed value is false. Is this possible? 回答1: You can setup an observable that control the flow and complete it when you are done. Also use zip operator - it

AngularFire Observables / Subscribe - Not Setting Class Variable in Same Scope

偶尔善良 提交于 2019-12-12 04:38:18
问题 I'm building an Ionic app using Firebase, and therefore AngularFire2. In Angularfire2 you can authenticate, but it's an observable and have to subscribe to get the user object. The problem is that I can't seem to set this.user = user because it doesn't seem like .subscribe is in the same scope. Here's an example, I have a auth.ts and an app.component.ts . In my service, I authenticate, auth.ts export class AuthService { // user: Observable<firebase.User>; user: object = { displayName: null,

Rx js filter method does not return the filter array

半世苍凉 提交于 2019-12-12 04:28:19
问题 I want to return filtered observable from Array, but when I am subscribing to this observable it does not return the filtered array, it returns the original array. why? const filterBy = {title: 'javascript'}; const items = [{title: 'javascript'}, {title: 'css'}, {title: 'html'}]; const filtered = Rx.Observable.of(items).filter(i => { const filtered = i.filter(item => item.title.indexOf(filterBy.title) !== -1); console.log('filtered', filtered); // The array length is one return filtered; })