The 'subscribe' attribute is not a part of the 'OperatorFunction<{},{>}' structure

Below is a snippet of code from my service file:

import { Injectable } from '@angular/core';
import { Http, Response } from "@angular/http";
import {map, catchError} from 'rxjs/operators';
import { Observable } from "../../node_modules/rxjs";

@Injectable({
  providedIn: 'root'
})
export class SessionService {
  BASE_URL = "http://localhost:3000"
  constructor(private http: Http) { }

  handleError(e) {
  return Observable.throw(e.json().message);
}

signup(formSignup) {
  return this.http.post(`${this.BASE_URL}/api/signup`, formSignup)
  .pipe(map(res => res.json())),
  catchError(this.handleError);
}

In the following code block, we are encountering an error related to the subscribe method:

import { Component, OnInit } from '@angular/core';
import { SessionService } from '../../services/session.service';
import { Router } from '@angular/router'

@Component({
  selector: 'app-signup-form',
  templateUrl: './signup-form.component.html',
  styleUrls: ['./signup-form.component.css']
})
export class SignupFormComponent implements OnInit {

  constructor(
  private sessionService:SessionService, 
  private router:Router) { }

  ngOnInit() {
  }

  sendSignupForm(myForm){
    this.sessionService.signup(myForm.value)
      .subscribe(()=> this.router.navigate(['private']))
    }
   }

I am facing an issue with subscribing to my API call in the service file. The error message being displayed is as follows:

The

subscribe' property does not exist in the
OperatorFunction<{}, {}>>' type

I am seeking assistance to resolve this error. Any suggestions or help would be greatly appreciated. Thank you.

Answer №1

Your signup function may have a couple of issues. With Angular 6, you no longer need the map(res => res.json()) part in your service. Additionally, there seem to be syntax errors in the function - perhaps missing parentheses or the . operator.

signup(formSignup) {
  return this.http.post(`${this.BASE_URL}/api/signup`, formSignup)
                  .catch(this.handleError);
}

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

The specified route type does not comply with the NextJS route requirements, resulting in an authentication error

Recently, I have encountered an issue with NextJS routes while working on an ecommerce project. I am seeking guidance to resolve this issue, specifically related to my route.ts file which interacts with NextAuth for providers like Google. During developmen ...

The callback function inside the .then block of a Promise.all never gets

I'm currently attempting to utilize Promise.all and map in place of the forEach loop to make the task asynchronous. All promises within the Promise.all array are executed and resolved. Here is the code snippet: loadDistances() { //return new Prom ...

Creating a multipart/form-data POST request in Angular2 and performing validation on the input type File

I am working on sending an image (base64) via a POST request and waiting for the response. The POST request should have a Content-Type of multipart/form-data, and the image itself should be of type image/jpg. This is what the POST request should look like ...

What is the best way to transform a Map<string, boolean> into an array of objects with key-value pairs {key: string, value: boolean

I'm currently working on a React project that incorporates TypeScript, and I've successfully implemented dynamic permission creation on the user creation page by utilizing this particular code snippet. The permissions being used on the page are m ...

Bringing in a feature within the Vue 3 setup

At the moment, I am attempting to utilize a throttle/debounce function within my Vue component. However, each time it is invoked, an error of Uncaught TypeError: functionTD is not a function is thrown. Below is the code snippet: useThrottleDebounce.ts imp ...

Array of class properties in Typescript

Is there a way to iterate through the properties of a class or a new object instance of that class when none of the properties are set? When I use Object.keys(), it returns an empty array because no properties have been initialized. How can I achieve this ...

Seeking a solution to the useRef problem. Encountering difficulties with React Hook useRef functionality within a NextJS application

Whenever I refresh the page, the 'Ref' value is displayed as null. This causes the if condition blocks not to work. I attempted to modify the useRef values but could only set it to null. When I console log the myDivRef.current, it returns "Ref: ...

Is there a way to enable intellisense in vscode while editing custom CSS within a material-ui component?

Is there a vscode extension recommendation for intellisense to suggest css-in-js for customized material ui components in .tsx files? For example, I want intellisense to suggest 'backgroundColor' when typing. The closest I found is the 'CSS- ...

Having trouble with reactjs and typescript? Getting the error message that says "Type 'string' is not assignable to type 'never'"?

When trying to setState with componentDidMount after an axios request is completed, you may encounter the error message Type 'string' is not assignable to type 'never'. Below is the code snippet: import * as React from 'react&apos ...

Is there a way for me to retrieve the text generated by OpenAI in the completion response?

let gptResponse = await openai .createCompletion({ model: "davinci", prompt, max_tokens: 60, temperature: 0.9, presence_penalty: 0, frequency_penalty: 0.5, best_of: 1, n: 1, stre ...

The expected function is being executed, yet none of the inner functions are invoked

Currently, I am working on unit tests for an Angular application using Jasmine and Karma. One particular unit test involves opening a modal, changing values in a form, and saving them. Everything goes smoothly until it reaches the promise inside the open() ...

Troubleshooting the createStyles Problem in Material UI with Typescript

I am currently working on implementing a test code following the guidelines provided in the Material UI typescript documentation. import * as React from 'react'; import { Theme } from '@material-ui/core/styles/createMuiTheme'; import ...

Issue with dynamic imports and lazy-loading module loadChildren in Jhipster on Angular 8, not functioning as expected

When utilizing dynamic import, it is necessary to modify the tsconfig.json file in order to specify the target module as esnext. ./src/main/webapp/app/app-routing.module.ts 14:40 Module parse failed: Unexpected token (14:40) File was processed with these ...

Angular 2, the change event is not triggering when a bootstrap checkbox is clicked

Encountering an issue, the (change) function is not triggering in a specific checkbox. <input [(ngModel)]="driver.glasses" name="glasses" type="checkbox" class="make-switch" (change)="changeFunction()" data-on-color="primary" data-off-color="info"&g ...

Tips for showcasing JSON data in an HTML table or list

I am seeking a way to dynamically display changing JSON object data in a table using Angular. The structure of the JSON object is subject to change due to server updates. JSON Object: { "This item has 1 value":1, "Another":30, "It ...

Using Jasmine to Jest: Mocking Nested function calls

I am currently working on testing my TypeScript functions with Jasmine: //AB.ts export async function A() { } export async function B() { A(); } My goal is to unit test function B by mocking out function A to see if it is called. Here is the code I h ...

What is the best way to combine two arrays and generate a new array that includes only unique values, similar to a Union

Here are two arrays that I have: X = [ { "id": "123a", "month": 5, "markCount": 75 }, { "id": "123b", "month": 6, "markCount": 85 ...

The CSS files are not loading automatically in my React application using Vite

I am facing an issue with importing css and js files into a view in React using vite. The styles are not loading properly, and I have to keep commenting and uncommenting the imports in my code for them to be recognized when entering the view. Below is a s ...

Using a React component with Material-UI style classes in TypeScript is not possible

Recently delving into react, I've embarked on a learning project utilizing typescript 3.7.2 alongside material-ui 4.11.0 and react 16.13.1. Initially, I structured my page layouts using functional components, but upon attempting to switch them to clas ...

Tips for efficiently handling input and output parameters in a dynamically generated component in Angular2 RC4

I need to pass several parameters to a component: <sentence [sentence]="text.title" [selectedWord]="selectedWord" (selectionChanged)="selectionChanged($event)"></sentence> To dynamically create a component, I am using the following code: ad ...