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' ";
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With