Accessing value of an Observable

Issue I have the following code: // Service import { Injectable } from ‘@angular/core’; import { HttpClient, HttpHeaders } from ‘@angular/common/http’; import { NbAuthService, NbAuthJWTToken } from ‘@nebular/auth’; interface PlatformInterface { id: number; name: string; } @Injectable() export class PlatformService

Continue reading

valueChanges event observable not caught in RXJS in angular

Issue In constructor I have: this.step1FormGroup = this.formBuilder.group({ firstLastName: new FormControl(”) }); this.step1FormGroup.get(‘firstLastName’).valueChanges.pipe( map((a) => { console.log(‘oy!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!’); return a; }) ); and in template I have this: <form [formGroup]="step1FormGroup"> <ng-template matStepLabel>Fill out your name</ng-template> <mat-form-field> <input matInput placeholder=’Last name, First

Continue reading

Invoke function in child component using a service injected in parent

Issue I have a function using a service call that must be invoked in both parent and child component. @Component({ selector: ‘my-app’, template: ` <app-child [callTheObservable]="callTheObservable"></app-child> <button (click)="callTheObservable()">button</button> `, styleUrls: [‘./parent.component.css’], }) export class ParentComponent { constructor(private customService: CustomService) {}

Continue reading

Combine subject and observer in a single subscribe RxJs

Issue I have an Behavior Subject private usersSubject: BehaviorSubject<ActionedUser[]> = new BehaviorSubject([]); public usersChange: Observable<ActionedUser[]> = this.usersSubject.asObservable(); constructor() { } set updatedUsers(users: ActionedUser[]) { this.usersSubject.next(users); } and an Observable getCurrentUser(): Observable<WebAuthUser> { if (environment.production) { return this.http.get<WebAuthUser>(`${this.webAuthURL}/wauth/api/user`, { withCredentials: true

Continue reading

Jest/Rxjs – timeout when calling for subscription from a getter

Issue I have a service that updates an Rxjs Subject whenever a method in the service is called: @Injectable() export class AppAlertService implements IAppAlertService { private readonly _alertBehaviourSubject: Subject<IAlertConfiguration> = new Subject<IAlertConfiguration>(); public get alertConfiguration(): Observable<IAlertConfiguration> { return this._alertBehaviourSubject.asObservable(); }

Continue reading

Wait for observable to complete

Issue I have series of methods which are dependent on completion of other methods. process1(data: string) : Observable<string> { this.dataservice.process(data).subscribe( (response) => { return response.data; } ); } main(data: string) : string { var process1Data: string = process1(data); // I

Continue reading

Angular bind formControl based on expression

Issue I have 2 arrays in my request data. One contains included products, other – excluded. You can’t use both at the same time. So i have such HTML: <input [formControl]="this.exclude$ ? excludedFormControl : includedFormControl> <mat-slide-toggle (change)="excludeChange($event.checked)"></mat-slide-toggle> Here is my

Continue reading

Initialize object with Subscribe

Issue i’m getting data from APIs and I’m inicializing the data like this: export class ForumComponent implements OnInit { @Input() id_foro: number = 3; nombre: string = ”; desc: string = ” foro!: Forum; constructor(private forumService: ForumService) { } ngOnInit():

Continue reading

Why observer method is called twice?

Issue I have the following method that returns observer, but it is called twice: public getClassesAndSubjects(school: number, whenDate: string): Observable<ClassesAndSubjects[]> { console.log(‘1’); const observable = this.classService.GetClassesAndSubjects(school, whenDate); console.log("2"); observable.subscribe(data => { if (!data.hasOwnProperty(‘errors’)) { this.classesSubjects = data; } }, error

Continue reading

Angular RXJS Sequential multiple post request

Issue I tried to do following function with concat map. but i’m not sure what is the correct way for that. //Req 01 await this.shippingInfoService.getShipmentInfoByCardId(this.data.CardId).then(async (shipmentData) => { if (shipmentData != undefined) { if (shipmentData.ShipmentId !== null && shipmentData.ShipmentId !==

Continue reading

Angular RXJS Sequential multiple post request

Issue I tried to do following function with concat map. but i’m not sure what is the correct way for that. //Req 01 await this.shippingInfoService.getShipmentInfoByCardId(this.data.CardId).then(async (shipmentData) => { if (shipmentData != undefined) { if (shipmentData.ShipmentId !== null && shipmentData.ShipmentId !==

Continue reading

Rxjs: map each element in an array field from an observable of object with another observable

Issue I have a method called getTransactionDetails(id:string), and it returns an Observable of TransactionDetails object getTransactionDetails(id:string):Observable<TransactionDetails> The TransactionDetails object looks like this: class TranscationDetails{ id:string; accessCode: string; veggiesList: Array<Veggie>; meatList: Array<Meat>; } The Veggie object looks like this: class Veggie{

Continue reading

when i subscribe my Observable, my next is not working

Issue myObservable():Observable<boolean>{ const result = new Subject<boolean>(); result.next(true); result.complete(); return result.asObservable(); } this.myObservable().subscribe(x=> console.log(x)); when i subscribe my Observable which function name is myObservable but the console never working this.myObservable().subscribe({ next: _response => {console.log(‘next’);} error: error => { console.log(‘had an

Continue reading

RxJs fromEvent combined with retryWith

Issue This is my code: const searchBooks$: Observable<Book[]> = fromEvent( this.filter.nativeElement, ‘keyup’ ).pipe( debounceTime(500), map((e: any) => { console.log(‘map’); return e.target.value; }), distinctUntilChanged(), concatMap((search) => this.bs.getBooks(search)), shareReplay(), retryWhen((errors) => { console.log(‘error.. retrying n 2 seconds’); return errors.pipe(delayWhen(() => timer(2000))); })

Continue reading

How can I test my service in Angular with Jasmine?

Issue I created a service which looks like this: @Injectable({ providedIn: ‘root’ }) export class NotificationService { private notifications: Notification[] = [] private readonly notifications$: Subject<Notification[]> = new Subject() getNotifications(): Observable<Notification[]> { return this.notifications$ } addNotification(config: Notification) { const newNotification

Continue reading

How to access properties in interface typescript

Issue Hi I want to access the property inside the interface from observable. I have two properties inside this interface. loan-grade.ts export interface LoanGrade{ grade:string subgrade: string } I use subscribe to access Observable<LoanGrade[]>. edit.component.ts grades: LoanGrade[]; ngOnInit():void{ this.termGradeServie.termGradeData$.subscribe(grades=>{ this.grades

Continue reading

Angular 5 convert Observable<obj> to obj

Issue I’m implementing resolve method: resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<Obj> | Obj { return this.service.get(route.params[‘guid’]) .map((response: Json) => { return this.service.list(response.data.id).map((response: Json) => { return <Obj>response.data; }); }); But I have error Can’t convert to Observable<Observable<Obj>>. How can I resolve

Continue reading

How to return boolean value from a function that subscribes to an observable of another function?

Issue I’m having this problem, I have a ProductService that has a boolean function validateProductsBeforeChanges. Inside validateProductsBeforeChanges I call a function from another service called OrderService which returns an observable. Some example code: validateProductsBeforeChanges(idProduct): Boolean { this._orderService.getAll() .subscribe(orders => {

Continue reading

Http post and get request in angular 6

Issue In angular 5.2.x for http get and post I had this code: post(url: string, model: any): Observable<boolean> { return this.http.post(url, model) .map(response => response) .do(data => console.log(url + ‘: ‘ + JSON.stringify(data))) .catch(err => this.handleError(err)); } get(url: string): Observable<any>

Continue reading