angular - 在不相关的 Angular 组件之间共享数据
问题描述
如本文所述,我正在使用服务在两个不相关的控制器之间共享数据
这是我用来共享数据的服务
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.appservice.file.subscribe 不是函数
解决方案
推荐阅读
- javascript - JavaScript,箭头函数
- python - 如何在 python 中使用 pdfkit 的 print-media-type 选项
- c# - 按名称获取服务
- sql - 如何在 postgresql 中查询空字符串?
- python - 在没有浏览器的情况下使用 Selenium 进行网页抓取
- mongodb - 使用 mongorestore 导入 CosmosDB MongoDB API 失败并出现可重试写入错误
- algorithm - 检查 DAG 中是否存在具有特定距离的节点
- java - 在多个传感器连接之间实现 wait() 和 notify()
- firebase - 有没有办法不使用内存中的身份验证?@PreAuthorize、@Secured、@RoleAllowed 不起作用
- javascript - JS - 这个循环如何使浏览器崩溃?