invoke the next function a different privateFunction within rxjs

I'm trying to figure out how to pass the resetPassword data to the _confirmToUnlock method in Typescript/RxJS. Here is my subscribe method:

 public invokeUnlockModal() {
   let resetPassword = { userName: this.user?.userName};    //i need to send this to _confirmToUnlock method
      this.infoModal.componentInstance.emitUserOp
                     .subscribe({ next: this._confirmToUnlock });
  }

This method is called when needed:

    private _confirmToUnlock = async (response: { opStatus: string }) => {
        
      if (response.opStatus.toLowerCase() === 'confirmed') {
          
//  let resultObs= this.dataService.unlockUser(resetPassword);
  //let result= await resultObs.toPromise();
         }
      }

If anyone has any ideas on how I can achieve this, please let me know.

Answer №1

I'm not really familiar with this specific Modal definition, but if it involves a simple callback, you can try using an arrow function to pass arguments.

You can attempt the following approach:

public openUnlockModal() {
  let passwordReset = { username: this.user?.username };
    this.infoModal.componentInstance.emitUserOp.subscribe({ 
      next: (response: any) => this._confirmUnlock(response, passwordReset)
    });
}

private _confirmUnlock = async (response: { status: string }, passwordReset: any) => {
  // utilize `passwordReset` here
  if (response.status.toLowerCase() === 'confirmed') {
  }
}

Furthermore, I recommend avoiding mixing Promises and Observables in your code as it can make maintenance challenging. It's best to either convert everything to Observables or vice versa.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How to customize Material UI Autocomplete options background color

Is there a way to change the background color of the dropdown options in my Material UI Autocomplete component? I've checked out some resources, but they only explain how to use the renderOption prop to modify the option text itself, resulting in a a ...

Filtering JSON by a specific value in Ionic 2 app

Recently, I've started working with Ionic 2 and Angular. I'm trying to filter a JSON data to display only specific values, like getting users by gender. Below is the code snippet I tried: home.html <ion-list> <ion-item *ngFor="let ...

There is no such property - Axios and TypeScript

I am attempting to retrieve data from a Google spreadsheet using axios in Vue3 & TypeScript for the first time. This is my initial experience with Vue3, as opposed to Vue2. Upon running the code, I encountered this error: Property 'items' does ...

This code snippet, document.location.search.replace('?redirect=', '').replace('%2F', ''), is failing to execute properly in Firefox

The functionality of document location search replace redirect to another page works in Chrome, however, document.location.search.replace('?redirect=', '').replace('%2F', ''); it does not work in Firefox; instead, ...

The mat-dialog component in Angular does not apply the styling of mat-button

I'm facing an issue with my Angular 9 project. Everything seems to be working fine, except when a mat-dialog is opened, the buttons inside it do not have the material-style applied. Strangely, this problem only occurs within the mat-dialog window. On ...

Identifying the end of a tree traversal using RxJS

I've hit a roadblock in my design process involving RxJS. Despite dedicating considerable time to studying the documentation, I haven't been able to find a solution. If anyone can offer some guidance... Currently, I'm navigating through a t ...

While attempting to set up a fresh 'TypeScript Angular Project' in Visual Studio 2022, I encountered an Error Message stating "Visual Studio Code: Illegal characters found in the path"

Encountering an issue when attempting to create a new 'Standalone TypeScript Angular Project' called HealthCheck in VS 2022. Upon clicking the create button, I receive an Error Message stating "Visual Studio Code: Illegal characters in path" for ...

Ways to implement logging in an NPM package without the need for a specific logging library

Currently, I am in the process of developing a company npm package using TypeScript and transferring existing code to it. Within the existing code, there are instances of console.log, console.warn, and console.error statements, as shown below: try { c ...

Leverage the power of TypeScript custom transformer and project reference for enhanced

I am currently working on a project that involves using both project references and custom transformers. The issue I am facing is that project references require the use of TSC for incremental compilation, but when TSC is used, the transformers are not app ...

How to access a deeply nested object in Angular 2

I am currently grappling with the challenge of extracting information from an object in a JSON response. The structure of the data is shown below: {"bpi":{"2017-10-03":4320.09,"2017-10-04":4225.9238,"2017-10-05":4322.755,"2017-10-06":4370.245,"2017-10-0 ...

Step-by-step guide for deploying an Angular 2 CLI app on GitHub

As a front-end engineer, I have limited experience with deployment. Currently, I am working on my pet project using angular-cli. What is the best way to deploy it on GitHub Pages? Are there any other straightforward methods for deployment? ...

Does Nativescript have a feature similar to "Hydration"?

It's been said that Phonegap offers an exciting feature called Hydration, which can lead to rapid and efficient deployments when combined with CD. Is it feasible to incorporate this concept into a Nativescript application? While I may not be well-ve ...

Encountering issues with React Nextjs - unable to utilize useState hook or

Hi everyone, I'm new to React and I think I might have overlooked something. I've been trying to create a simple registration form, but it seems like I'm having trouble changing the state. ` import {useState} from 'react' export ...

Angular 7: Unable to connect with 'messages' because it is not recognized as a valid attribute of 'message-list'

Currently, I am embarking on an Angular journey to develop a hobby chat project using Angular 7 for educational purposes. My main hurdle lies in comprehending modules and components, which has led me to encounter a certain issue. The Challenge In the tut ...

Tips for implementing validation in template-driven form using Ionic 3

How can I validate a mobile number in an Ionic 3 application? I am using ngModel, but I'm looking for an example to help me with the validation process. Can anyone provide guidance on how to do this? <ion-list> <ion-item margin ...

Is it possible to utilize a React component within the DataGrid cell instead of the standard cell types like 'string', 'number', 'date', and 'dateTime' in Material UI?

Using React, Material UI, and TypeScript I am trying to embed a React component into the cell of a DataGrid but have encountered an issue. I have explored custom column types for cells here, however, it only allows me to manage string formats, whereas I ...

Toggle the disable state of a button depending on a specific condition

I have a scenario where I am fetching data from a server, and I need to apply a filter to a specific column. The requirement is that if the "bought" column (boolean) has a value of true, then the edit button should be disabled; otherwise, it should be enab ...

Retrieve all items that match the ids in the array from the database

I'm having trouble receiving a list of items that match with my array of ids. Here's a snippet from the Angular component code: this.orderService.getSpecyficOrders(ids) .subscribe(orders => { ... Where ids is an array of [{_id : ID }, ...

The HTML button triggers a function to execute on a different webpage when clicked

I'm facing a straightforward issue that I can't seem to figure out due to my limited experience with Angular and web development. The problem revolves around two components, namely home and dashboard. In the home.component.html file, there's ...

What is the predefined value for a multi-select generated by the ng-for directive in Angular?

I am having trouble setting default selected values for the multi-select. Despite trying various methods such as initializing the ngModel to bind the variable and using [selected] = "selectedSegment == 'S1'", none of them seem to be effective fo ...