我有一个Angular 2服务,用于两个子组件之间的共享信息,两个组件都与服务良好通信,但我无法将变量的值设置到服务中。这是服务代码:
import { Injectable } from '@angular/core';
import { Http, Headers, Response } from "@angular/http";
import { Observable } from "rxjs";
import { Subject } from 'rxjs/Subject';
import {BehaviorSubject} from 'rxjs/Rx';
import 'rxjs/Rx';
@Injectable()
export class ServiceNotifications {
newPacient: boolean;
nuevoPacient$: Subject<boolean> = new BehaviorSubject<boolean>(this.newPacient);
constructor() {
this.newPacient$.asObservable();
}
notiNewPacient(status:boolean){
console.log(status);
this.newPacient=status;
this.newPaciet$.next(this.newPacient);
}
}
我的问题是我无法使用函数notiNewPacient()更新变量newPacient。