类型'Observable <any>'上不存在属性'next'

Bah*_*eol 9 angular5

我正在学习角度5,我一直在尝试使用.next方法添加data.service.ts尝试这个:

import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';

@Injectable()

export class DataService {

  private go = new BehaviorSubject<any>([' First Goal','Second Goal']);

  newvar = this.go.asObservable();

  constructor() { }

  changeGoal(newvar){
    this.newvar.next(this.go);
  }

}
Run Code Online (Sandbox Code Playgroud)

我收到了这个错误:'Observable'类型中不存在"属性'下一个'";

小智 9

由于.next()是 a 的属性Subject而不是 an 的属性Object,因此您应该使用go.next()而不是this.newvar.next()

changeGoal(newvar) {
    this.go.next(value);
}
Run Code Online (Sandbox Code Playgroud)