属性'next'不存在,类型为'Observable '

问题描述 投票:9回答:1

我正在学习角度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);
  }

}

并且我得到这个错误:“类型'Observable'上不存在属性'next'”]]

我正在学习angular 5,我一直在尝试使用.next方法添加data.service.ts。从'rxjs / ...

angular5
1个回答
0
投票

使用go.next(),而不是this.newvar.next(),然后

changeGoal(newvar){
 this.go.next(value);
© www.soinside.com 2019 - 2024. All rights reserved.