Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Property 'next' does not exist on type 'Observable<any>'

Tags:

angular5

I am learning angular 5 and I have been trying to use the .next method to add data.service.ts In trying this :

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

}

and I got this error: " Property 'next' does not exist on type 'Observable' ";

like image 340
Bahadur Singh Deol Avatar asked Dec 05 '17 13:12

Bahadur Singh Deol


1 Answers

Since .next() is a property of a Subject and not of an Object, you should use go.next() instead of this.newvar.next():

changeGoal(newvar) {
    this.go.next(value);
}
like image 173
karthik venna Avatar answered Sep 21 '22 19:09

karthik venna