Property 'subscribe' does not exist on type '() => Observable'

前端 未结 2 1321
情深已故
情深已故 2020-12-30 02:08

service file

import { Observable } from \'rxjs/Rx\';
import { Http,Response} from \'@angular/http\';
import { Injectable } from \'@angular/core\';
import \'         


        
相关标签:
2条回答
  • 2020-12-30 02:49
    ngOnInit() {
        this.videoserv.getvideos().subscribe((response) => {
             this.videos = response
        });
    }
    

    You should be calling the getvideos() method on the videoserv service. You were missing the (), getvideos is a method not a property.

    0 讨论(0)
  • 2020-12-30 02:55

    You are not calling the getVideos method. You are calling subscribe on the function reference of getVideos and not the returned value. Call subscribe after you call getVideos():

    ngOnInit() {
        this.videoserv.getvideos().subscribe((response) => {
             this.videos = response
        });
    }
    
    0 讨论(0)
提交回复
热议问题