rxjs

Angular Material Table own datasource with filter method

泄露秘密 提交于 2019-12-08 00:55:29
问题 With the help of this tutorial I wrote my own datasource for the angular material table. I get the list of data from an api and display it in a material table. Code MyDataSource export class MyDataSource extends DataSource<any> { private users: Observable<User[]>; constructor(private userService: UserService) { super(); } connect(): Observable<User[]> { this.users = this.userService.getAll(); return this.users; } disconnect() { } filterWithCriteria(filterData: any): any { return this.users

Why a 'next' before 'complete' of Angular takeuntil ngUnsubscribe?

若如初见. 提交于 2019-12-07 23:20:59
问题 There are tons of info out there on using 'takeUntil' operator to unsubscribe from a stream, like so: ... export class CategoryOptionInputComponent constructor(private svc: MyService, protected router: RouterService) { ... this.router.routerUrl$.pipe(takeUntil(this.ngUnsubscribe)).subscribe(s => { const param1 = s.state.featureId; this.svc.InitFromApi(param1); }); ... } ngOnDestroy() { this.ngUnsubscribe.next();//<-- This line is confusing this.ngUnsubscribe.complete(); } private readonly

Angular 2 set input max length dynamically

让人想犯罪 __ 提交于 2019-12-07 22:08:48
问题 I would like to get the max length of an input from a service (do an http call to get the value). Is there any way to do it with calling the service only once? <input type="text" [attr.maxLength]="getMaxLength()/> thanks 回答1: Setting maxLength attribute value to a class property which value is set in contructor or ngOnInit will make it stop calling the service anymore HTML: <input type="text" [maxLength]="maxLength"/> Typescript maxLength: number; ..... constructor(private myService:

How to use retryWhen with a function that returns a Boolean?

≯℡__Kan透↙ 提交于 2019-12-07 20:55:52
问题 Here's my code: this._http.post(this._url_get + extension, '', { headers: headers }) .map(res => res['_body']) .retryWhen(errors => {return responseErrorProcess(errors)}) now I need to catch exceptions and pass them to my responseErrorProcess() which returns true if it needs to retry I could not figure out how to retrieve the exceptions from errors , this is how it looks: Subject_isScalar: falseclosed: falsehasError: falseisStopped: falseobservers: Array[0]thrownError: null__proto__:

Ionic 2 http.get() issue

点点圈 提交于 2019-12-07 20:13:10
问题 I tried to make a http.get() call with these two methods. First: getResults(){ return this.http.get('http://localhost/api.php') .toPromise() .then( data => data.json() ); } Error Shown: 3 122412 error EXCEPTION: Uncaught (in promise): Response with status:0 for URL: null 4 122413 error ORIGINAL STACKTRACE: 5 122413 error Error: Uncaught (in promise): Response with status: 0 for URL: null .......... Second: getResults(){ return new Promise((resolve, reject) => { this.http.get('http://localhost

RxJS not all Subscribers receive all events

Deadly 提交于 2019-12-07 20:03:59
问题 I'm working on an exercise about RxJS. And there's something very strange happening: typoStream.subscribe(x => console.log('wont get executed')); wordCompletedStream.subscribe(nextStream); typoStream.subscribe(x => console.log('will get executed')); When the application runs the first console.log won't get printed and the second one will. Regardless of what the streams are and how they interact - this should never happen, right? Why is it important when I subscribe to an observable - shouldn

Concatenation of Angular http requests

怎甘沉沦 提交于 2019-12-07 19:41:31
问题 I am facing the following scenario. There is a Front End app, built with Angular(2), which is connected with a REST Back End accessible via http. Once an user logs in (using email and pwd), the Back End returns data related to the user and in particular an id associated with the user (let's call this userId ) and the code of the region where he lives (let's call this regionId ). Via the userId I can query the Back End to get the affinity group ID to which the user belongs (let's call this

How onComplete actually works in RxJS

感情迁移 提交于 2019-12-07 19:25:14
问题 Observables complete naturally if they are constructed from finite data. import {Observable, Subject} from "rx"; let stream0$ = Observable.of("1", "2", "3"); let stream1$ = stream0$.map(x => x); stream1$.subscribe( (val) => { console.log("onNext", val) }, (err) => { console.log("onError", err) }, () => { console.log("onCompleted") } ); // onNext 1 // onNext 2 // onNext 3 // onCompleted Or don't if not. But what about observables subscribed on subjects? For example: import {Observable, Subject

RxJS异步通信之map、flatMap

你。 提交于 2019-12-07 19:04:31
let source1: string = Observable.range(1,4).map((item) => { return item; }); source1.subscribe((itam) => { console.log('return value: ' + item); }); return value:1 return value:2 return value:3 return value:4 let source2: string = Observable.range(1,4).flatMap((item) => { return Observable.of(item); }); source2.subscribe((itam) => { console.log('return value: ' + item); }); return value:1 return value:2 return value:3 return value:4 在RxJS中map和flatMap都可以对单个对象进行操作,最主要的区别在于返回的数据类型,map的返回就是原本的数据类型即可,而flatMap返回的是一个流数据,即要在数据返回是增加Observable的转换。 这里的return的单粒的,如果想直接返回一个数组,直接使用toArray()方法即可。 let source2

Add data to http response using rxjs

余生长醉 提交于 2019-12-07 18:18:40
问题 I have a trip entity which contains driver id. I can get fetch trip using RESTFull endpoint, e.g. /trips/2/ . //example response { id: "2", driver_id: "123" } I can fetch driver details using the endpoint. e.g. /drivers/123/ , My final respected response is //expected response from observable { id: "2", driver_id: "123", detailed_driver: { name: "abc", id: "123" } } Currently I do it as follows this.http("/trips/2/").map(data => data.json()).subscribe(trip => { this.http("/drivers/" + trip