rxjs

Is there some sort of Priority operator on RxSwift?

别等时光非礼了梦想. 提交于 2020-02-05 02:30:12
问题 I have a textfield that has 2 rules for validation: minimum amount of chars and alphanumerical chars. I want to be able to represent to the user what he's doing wrong in an error label but the problem is that if I bind the textfield to both rules it can be creepy because once one rule gets approved the ui does a little flickering from the color of the separator for example changing from red to green to red because of the other validation failing. I'd like to know if there's a way to

RxJS dynamic source of observables

前提是你 提交于 2020-02-04 05:30:48
问题 I want to create an Observable of many observables (merge them). This could be achieved with merge(...arrayOfObservables) . The problem is that some time this array will be changed and the observable should subscribe to the new observables, too. 回答1: You can push new Observables to an array and then emit the array and subscribe to them with switchMap . import { of, merge, BehaviorSubject } from 'rxjs'; import { switchMap } from 'rxjs/operators'; const s = new BehaviorSubject([of(1), of(2), of

Using subjects in Angular 2

半世苍凉 提交于 2020-02-03 10:46:46
问题 My main.service.ts @Injectable() export class AppService{ private mainSource = new Subject<boolean>(); main$ = this.mainSource.asObservable(); } My app.component.ts constructor(private appService: AppService){ this.appService.main$.subscribe( working => {this.appService.main$(false);} } ngOnInit(){ if (this.appService.main$){alert("Tio");} } My app.component returns a Cannot invoke an expression whose type lacks a call signature error. And my OnInit alert fires regardless of whether or not

JS-异步

雨燕双飞 提交于 2020-02-03 00:41:30
回调函数 Promise RXJS 例子使用 angular 框架,创建了 一个服务 和 一个组件 服务 // promise 是 es6 新功能,不用导入第三方包 // rxjs是angular自带类,所以直接导入 import { Observable } from 'rxjs' ; public getCallbackType ( cb ) : void { setTimeout ( ( ) => { let type : string = "data by callback" ; cb ( type ) ; } , 1000 ) } public getPromiseType ( ) : any { // resolve 成功,reject 异常 return new Promise ( ( resolve , reject ) => { setTimeout ( ( ) => { let type : string = "data by promise" ; resolve ( type ) ; } , 1000 ) } ) } public getRxjsType ( ) : any { // observer.next 成功,observer.error 异常 return new Observable ( ( observer ) => { setTimeout (

Re-using an RxJS Observable to repeat an asynchronous call?

末鹿安然 提交于 2020-02-02 13:04:31
问题 How can an RxJS Observable emit a new value, if the underlying event stream doesn't emit a new value? Given an Angular component which uses an async pipe to display a user's name; export class MyComponent implements OnInit { public user$!: Observable<User>; constructor(private readonly ms: MyService) ngOnInit() { this.user$ = this.ms.getUser(); } } <ng-container *ngIf="user$ | async as user; else empty"> {{ user.name }} </ng-container> <ng-template #empty> No user here. </ng-template> ..

Delay for every element with RXJS

帅比萌擦擦* 提交于 2020-02-02 12:24:29
问题 I'm using RxViz to simulate different actions that comes every 1 sec. When I try Rx.Observable.create(obs => { obs.next([1, 2, 3]); // or could be ['aaa', 'bbbb', 'ccc'] obs.complete(); }).delay(1000); on https://rxviz.com or on my own with a console.log it keeps displaying the three number 1, 2, 3 at the same time There's a post about this same problem, but none of the answer works for me. I'm using Rx last version 6 How can I create an observable with a delay [EDIT] The array can contains

Filter array of objects by property value

↘锁芯ラ 提交于 2020-01-30 10:35:07
问题 I'm new with Angular and observables. I'm getting from a JSON file a list of products. products.service getProducts(): Observable<Product[]>{ return this._http.get<Product[]>(this.configUrl); } products.component products: Product[]; getProducts(): void{ this.productsService.getProducts() .subscribe(products => this.products = products); } product.ts export interface Product { "quantity": number; "price": string; "available": boolean; "sublevel_id": number; "name": string; "id": string; }

Can't read websocket on angular

怎甘沉沦 提交于 2020-01-30 05:45:11
问题 I am trying to exchange info through websockets between an Angular 8 app and a simple server. Strangely I'm able to send info to the server, but I can't seem to find how to wire the app to receive back my echoes. Here's the app component : import { Component } from '@angular/core'; import { webSocket, WebSocketSubject } from "rxjs/webSocket"; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { ws :

Angular http

安稳与你 提交于 2020-01-26 17:01:10
前端应用都需要通过 HTTP 协议与后端服务器通讯, @angular/common/http 中的 HttpClient 类为 Angular 应用程序提供的 API 来实现 HTTP 客户端功能。它基于浏览器提供的 XMLHttpRequest 接口。 HttpClient 带来的其它优点包括:可测试性、强类型的请求和响应对象、发起请求与接收响应时的拦截器支持,以及更好的、基于可观察(Observable)对象的 API 以及流式错误处理机制。 1.使用http服务 在根模块 AppModule 导入 HttpClientModule。因为大多数应用中,多处多都要使用到http服务,所以直接导入到根模块去。 import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { HttpClientModule } from '@angular/common/http'; @NgModule({ imports: [ BrowserModule, HttpClientModule, ], declarations: [ AppComponent, ], bootstrap: [ AppComponent ] }) export

Is possible to do a custom binder on an array of input fields using RxSwift?

时光总嘲笑我的痴心妄想 提交于 2020-01-25 10:13:51
问题 I have two input fields, one for password and another one to confirm the password. I want to create a custom binder that will allow me to compare the value of both input fields but also validate minimum amount of chars. I had a pretty similar question but not regarding comparing two different fields (Is there some sort of Priority operator on RxSwift?) and based on the answer for that previous question I've been trying to do something like this: enum PasswordCreateValidation { case valid case