rxjs

Is it possible to pass data after initializing the components?

北慕城南 提交于 2021-02-20 02:36:27
问题 I have three components as shown on the image below and use a custom form component in my feature component. However, there is not a direct parent-child relationship between these two components and there is also a form component between them. I pass data from feature to form using @Input propert that has input values inside a config data (let's say "configData") and then pass them to custom component via @Input property (let's say "configData.test" for test input) without any problem (I can

RxJS unsubscribe from inner observable when the source completes

痴心易碎 提交于 2021-02-19 08:40:14
问题 I have a function that returns observable that automatically unsubscribe when some internal thing happens using a Subject. Here is a simple version that shows the issue: const subject = new Subject(); const source = fromEvent(document.querySelector("h1"), "click").pipe( takeUntil(subject) ); fromEvent(document.querySelector("p"), "click").subscribe(() => { subject.next(); }); The issue is that if someone subscribes source and uses higher-order observable, it will not subscribe from the inner

ForkJoin Issue on angular

隐身守侯 提交于 2021-02-19 05:44:18
问题 I make this code for test forkJoin but it does not work! Can you check what is the problem? const observables = []; observables.push(new Observable(subscriber => subscriber.next('Hello'))); observables.push(new Observable(subscriber => subscriber.next(' '))); observables.push(new Observable(subscriber => subscriber.next('World') )); observables.push(new Observable(subscriber => subscriber.next('!'))); forkJoin(observables).subscribe(word => console.log(word.join(''))); 回答1: Try this const

How to merge or groupBy toPromise via RxJs?

僤鯓⒐⒋嵵緔 提交于 2021-02-19 05:39:08
问题 I have the following method that returns result as shown below: result: [ { status: 200, ... }, { status: 200, ... }, { status: 400, ... }, ... ] I need to group the result by using status value and return only 2 results instead of 3 for the example result above: update() { this.demoService.update(...).toPromise() .then(result => { const message = result.map((x: any) => { if (x.status === 200) { return { text: 'successful' }; } else { return { text: 'fail' }; } }); } }) } I tried to use

How to use RxJS, MySQL and NodeJS

北城以北 提交于 2021-02-19 05:34:17
问题 I need a with RxJS for MySQL in NodeJS. Could someone give me an example for one select? On front-end I will use Angular2. 回答1: In my case, I'm using the MySQL npm package in a desktop application made with Electron and Angular. However the same should work even on a plain NodeJS application by installing and importing rxjs. I've first installed mysql and @types/mysql package with: npm install --saved-dev mysql @types/mysql Then I've created a MySQL service: import { Injectable } from '

What is the benefit of using observable in Angular 5 http requests?

只谈情不闲聊 提交于 2021-02-19 05:12:18
问题 I am confused about using httpclient in angular 5.I am new to angular and just following the official angular tutorial.I dont know much about observables,promise,pipe etc..Currently I am having a service for handling all the http methods.For post request I am using with pipe.Below is the method. create(model: any,URI) :Observable<Object>{ return this.http.post(API_URL+URI, model) .pipe( catchError(this.handleError('create', model)) ); } private handleError<T> (operation = 'operation', result?

Will overwriting my observable variable kill current subscribers?

会有一股神秘感。 提交于 2021-02-19 03:05:55
问题 I want to be able to cache an http call, but also force the cache to refresh. My service looks like this: @Injectable() export class UserService { private currentUser$: Observable<User>; constructor(private http: HttpClient) { } getCurrentUser(force = false): Observable<User> { if (!this.currentUser$ || force) { this.currentUser$ = this.http.get<User>(`${environment.API_URL}/profiles/me`) .pipe( shareReplay(CACHE_SIZE) ); } return this.currentUser$; } } If I call getCurrentUser(true) , the

rxjs: perform some action regulary with specific delay in between

北战南征 提交于 2021-02-18 21:10:49
问题 Client applications sends request to server, that could potentially take long to complete. Once request is finished or failed, client should wait some period of time (i.e. 10 seconds) and then again send the request. Current working solution is this: appRequest = new Subject(); ngOnInit(): void { this.appRequest.delay(10000).subscribe(() => this.refresh()); this.refresh(); } refresh() { this.api.getApplications().subscribe(a => { this.updateApplications(a); this.appRequest.next(); },() =>

Angular 4+ 修仙之路

天大地大妈咪最大 提交于 2021-02-18 20:35:26
Angular 4.x 快速入门 Angular 4 快速入门 涉及 Angular 简介、环境搭建、插件表达式、自定义组件、表单模块、Http 模块等 Angular 4 基础教程 涉及 Angular CLI 使用、创建组件、事件、自定义服务、 ngFor 指令、Input、Output 装饰器等 Angular 4 指令快速入门 涉及如何创建指令、定义输入属性、事件处理、如何获取宿主元素属性值、如何创建结构指令等 Angular 4 表单快速入门 涉及如何创建表单、表单验证、表单控件状态、单选控件、多选控件的使用等 Angular 表单简介 涉及 Template-driven 表单与 Reactive 表单的特点、表单控件状态、Reactive 表单简介等 Angular 4.x 路由快速入门 涉及路由简介、如何配置路由、动态路由、子路由、路由指令及路由相关 API 等 TypeScript 简介 涉及 TypeScript 数据类型、复合类型、箭头函数、可选参数、默认参数、对象解构、数组解构等 Angular 4.x 组件学习线路 (仅供参考) 对于刚从 Angular 1.x 转到 Angular 4.x 的用户,建议先阅读一下 Angular 4.x vs Angular 1.x 章节 (目前还不够完善)。下面提供的学习线路仅供参考,读者可以自行选读

How to Check for a NULL Result from an Angular 5 RxJS Observable during Subscription?

落爺英雄遲暮 提交于 2021-02-18 15:09:25
问题 With RxJS Observables within Angular this.myService.getEmp(personEmpId).subscribe( result => { this.personName = result.person_name; }, error => { console.log("EE:",error); } ); How can I test if my subscription to this service returns a NULL result, i.e. no record was found at all? I tried adding the error part but this did not fire the console message. At the moment, I seem to be getting the following error message: ERROR TypeError: "result is null" 回答1: You can add a filter before