Troubleshooting the failure of chaining functions in Angular2 during an HTTP request

I want to organize functions based on their specific roles in the code

Here's the situation: when I'm making an http request, I want to separate the function that handles attaching the access token and headers from the one responsible for actually making the http call

In my reset password form (reset-password.html), I have:

<button (click)="tryResetPassword()">Reset Password>

In the reset-password.ts file:

tryResetPassword(){
  ..fetch form data
 return this._authService.resetPassword()
        .subscribe(
          ...handle response here
          )
 }

In the authService:

resetPassword(data):Observable<any>{
const body = JSON.stringify(data);  
return this.httpClient.post(this.authUrl + '/default/resetPwd', body)
     .map(
       res=>{
          //set access token
           return true
          }
        )

 }

Now in the _httpClient:

post(url, data) {
   let headers = new Headers();
   this.createGeneralHeaders(headers);

   return this.http.post(url+this.accessToken, data, {
     headers: headers
    });

After running the app, I'm encountering an error:

this._httpclient.post(...).map is not a function

Note: the http in the httpClient refers to angular2 http passed through the constructor

Where am I making a mistake?

Answer №1

Consider adding the map operator to your authservice

import 'rxjs/add/operator/map';

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

Building a like/dislike feature in Angular

Here is a snippet of code I have that includes like and dislike buttons with font-awesome icons: <ng-container *ngFor="let answer of question.answers"> <p class="answers">{{answer.text}} <i class="fa fa-hand-o-le ...

The global CSS styles in Angular are not being applied to other components as expected

Currently utilizing Angular v10, I have a set of CSS styles that are meant to be used across the entire application. To achieve this, I added them to our global styles.css file. However, I'm encountering an issue where the CSS is not being applied to ...

What led the Typescript Team to decide against making === the default option?

Given that Typescript is known for its type safety, it can seem odd that the == operator still exists. Is there a specific rationale behind this decision? ...

Using React, TypeScript, and Next.js to transform all elements in a static array to their last occurrence

I'm having trouble updating my array. Every time I click the button for the second time, only two or more records are added, similar to the last one I added. Does anyone know how to fix this issue? In the images below, you can see the results of the ...

Efficiently communicating updates to clients after executing multiple HTTP requests simultaneously in RxJS

Objective: Execute multiple asynchronous HTTP requests simultaneously with RxJS and trigger a callback after each request is completed. For instance: fetchData() { Observable.forkJoin( this.http.get('/somethingOne.json').map((res:Re ...

Upon attempting to run ionic for iOS, an error was encountered regarding the arm64 and armv7 architectures

I'm currently in the process of developing a mobile application for both Android and iOS platforms utilizing Ionic version 1. Here is a breakdown of the software versions I'm working with: cordova: 7.0.1 ionic: 2.2.2 ios-deploy: 1.9.2 ios-sim: ...

Angular 2: Finding the object with the highest attribute value in an array of objects

I am currently developing an Angular 2 application and I have an array of objects. My goal is to return the object that has the maximum value of a specific attribute (in this case, the object with the most likes). How can I achieve this in TypeScript? i ...

Tips for integrating Tinymce in Angular 2 once it has reached its stable version

How to Implement TinyMCE in Angular 2 with Two-Way Binding Working with Third-Party Libraries in Angular 2 After trying multiple solutions provided on stackoverflow, I am still unable to load the TinyMCE editor successfully. I am wondering if there are ...

What effect does choosing an image in my user interface have on halting my Web API?

When launching my .NET Core 3 Web API in Visual Studio 2019, everything runs smoothly and handles requests without issue. However, an unexpected problem arises when I interact with my Angular UI. Upon navigating to a new section designed for selecting fil ...

Date Polyfill with Internationalization API in Angular 4/Angular-cli is not functioning as expected

I am struggling to make the polyfill of the Internationalization API work properly. The documentation (https://angular.io/docs/ts/latest/guide/pipes.html) states that all you need to do is add a script to your index.html: <script src="https://cdn.poly ...

Angular: implementing lazy loading module specifically for development environment (environment.production === false)

I have a lazy loaded module specifically for development purposes and I do not want to include it in the production build. To prevent activation and loading, I have implemented a guard: const routes: Routes = [ { path: 'dev', loadChil ...

Leveraging the OpenLayers Map functionality within an Angular service

I am curious to learn if there is a way to utilize a service in Angular for creating an OpenLayers map and then passing that service to other components to update the map based on interactions within those components. I have outlined my approach below. Des ...

One way to update the value of the current array or object using ngModel in Angular 2 is to directly

I have a situation where I am dealing with both an array and an object. The array is populated with data retrieved from a service, while the object contains the first element of that array. feesEntries: Array<any> = []; selectedFeesEntry: any; clien ...

The NgModel variable, which is exported through Angular7 template driven validation, appears to be returning an

Trying to set up a straightforward template-driven form validation, I encountered an issue with #password="ngModel". When I check password.length, it returns undefined and I'm not sure why. Here is my Angular form: <form #f="ngForm"> <inp ...

Hiding the header on a specific route in Angular 6

Attempting to hide the header for only one specific route Imagine having three different routes: route1, route2, and route3. In this scenario, there is a component named app-header. The goal is to make sure that the app-header component is hidden when t ...

How can I distinguish between the multiple lists returned by the Web API and store them in separate arrays?

My web API returns multiple lists, such as employersList and locationsList. Here is the current code I am using: items = []; constructor(private http: HttpClient) {} getMember(){ this.http.get('http://apirequest').toPromise().then(da ...

Rendering illuminated component with continuous asynchronous updates

My task involves displaying a list of items using lit components. Each item in the list consists of a known name and an asynchronously fetched value. Situation Overview: A generic component named simple-list is required to render any pairs of name and va ...

What are some creative ways to emphasize certain dates?

Is there a way to customize mui-x-date-pickers to highlight specific days from a Date array with green filled circles around them? I am using new Date and wondering how to achieve this effect. Below is the code snippet I am currently working with: <Dat ...

Increase the totalAmount by adding the product each time

Can someone help me understand why the totalAmount shows as 20 when I add a product? Also, why doesn't it increase when I try to increment it? Any insights would be appreciated. Thank you. ts.file productList = [ { id: 1, name: 'Louis ...

React Navigation Browser

While developing my application, I encountered an error that I can't seem to resolve. It seems to be related to how I defined the routes in the code. Originally, the app had only one route, but after making changes to have multiple routes, I started g ...