@jfsoftwarellc wrote:
Try to relearn how to use http in Ionic 4 so I can do a sign up process. Tried following this article but something is off.
API Service
import { Injectable } from '@angular/core'; import { HttpClient, HttpHeaders, HttpErrorResponse, HttpParams } from '@angular/common/http'; import { Observable, of, throwError } from 'rxjs'; @Injectable({ providedIn: 'root' }) export class ApiService { url: string = 'http://localhost:3000'; constructor(public http: HttpClient) { } post(endpoint: string, body: any, reqOpts?: any): Observable<any> { return this.http.post(this.url + '/' + endpoint, body, reqOpts); } }
User Service
import { Injectable } from '@angular/core'; import { ApiService } from './api.service' @Injectable({ providedIn: 'root' }) export class UserService { _user: any; constructor(public api: ApiService) { } signup(accountInfo: any) { this.api.post('users.json', { user: accountInfo }).subscribe(res => { console.log(res); }, err => { console.log(err); }); } }
Error
“ERROR in src/app/signup/signup.page.ts(28,36): error TS2339: Property ‘subscribe’ does not exist on type ‘void’.”I was getting that property ‘subscribe’ does not exist on type ‘Observable’ but now I’m just getting void. Not sure what I changed to get void instead but either way, it no work.
Posts: 1
Participants: 1