如本文所述,我正在使用服务在两个不相关的控制器之间共享数据
这是我用来共享数据的服务
import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class AppService {
tempfile = "temp";
file: BehaviorSubject<string>;
count: BehaviorSubject<number>;
constructor() {
this.file = new BehaviorSubject(this.tempfile);
}
}
我将此服务注入了我的组件,但是当我尝试从服务中获取价值时
this.appsevice.file.subscribe(c => {
this.file = c;
});
我不断收到以下错误
this.appsevice.file.subscribe不是函数