Christiaan
Christiaan

Reputation: 21

Property 'subscribe' does not exist on type 'OperatorFunction<unknown, any>'

I'm trying to get some data from mongodb, and keep getting this error:

Property 'subscribe' does not exist on type 'OperatorFunction'

//app.component.ts

import { Component } from '@angular/core';
import {FormGroup, FormControl, Validators, FormsModule} from '@angular/forms';
import {CommonService} from './common.service';
import {Http, Response, Headers, RequestOptions} from '@angular/http';
import { Observable } from 'rxjs/Observable';
import { map } from 'rxjs/operators';
import { from } from 'rxjs';

@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.css']
})
export class AppComponent {

    constructor(private newService: CommonService) {
    }

    Repdata;
    valbutton = "Save";

    ngOnInit() {
        this.newService.GetProcesses().subscribe(data => this.Repdata = data);
    }
}

//common.service.ts


import { Injectable } from '@angular/core';
import {Http, Response, Headers, RequestOptions } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import { map, tap } from 'rxjs/operators';
import 'rxjs/add/operator/do';
import 'rxjs/Rx';
import { catchError } from 'rxjs/operators';

@Injectable()
export class CommonService {

    constructor(private http: Http) { }

    GetProcesses(){
        return this.http.get('http://localhost:4000/getProcesses/')
                   .pipe(map((response: Response) => response.json())),
            catchError(error => Observable.of(null))

    }
}

Property 'subscribe' does not exist on type 'OperatorFunction'

Upvotes: 2

Views: 5538

Answers (1)

Franco Roura
Franco Roura

Reputation: 817

It seems you have a misplaced parenthesis in your common.service.ts file.

I made this code snippet for you to try it out, hope it does what you need

// common.service.ts

import {Injectable} from '@angular/core';
import {Http, Response} from '@angular/http';
import {Observable} from 'rxjs/Observable';
import {catchError, map} from 'rxjs/operators';
import 'rxjs/add/operator/do';
import 'rxjs/Rx';

@Injectable()
export class CommonService {

    constructor(private http: Http) {
    }

    GetProcesses() {
        let url = 'http://localhost:4000/getProcesses/';
        return this.http.get(url).pipe(
            map((response: Response) => response.json()),
            catchError(error => Observable.of(null))
        );
    }
}

Upvotes: 2

Related Questions