类型'OperatorFunction< unknown,any>'上不存在属性'subscribe' [英] Property 'subscribe' does not exist on type 'OperatorFunction<unknown, any>'

查看:175
本文介绍了类型'OperatorFunction< unknown,any>'上不存在属性'subscribe'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从 mongodb 获取一些数据,并不断收到此错误:

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

类型"OperatorFunction"上不存在属性"subscribe"

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

//app.component.ts

//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

//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))

    }
}

类型"OperatorFunction"上不存在属性"subscribe"

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

推荐答案

似乎您的 common.service.ts 文件中的括号位置错误.

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

// 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))
        );
    }
}

这篇关于类型'OperatorFunction< unknown,any>'上不存在属性'subscribe'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆