angular - 我在页眉上显示的行为主题没有刷新
问题描述
在我的电子商务的标题上,我显示了我的购物车元素的行为主题计数器,每次点击添加到购物车后都会更新这个计数器,但它不显示新值,是因为标题加载了一个时间?
标头 ngOnInit 函数:
ngOnInit() {
this.itemCount = this.shoppingCartService.countBS;
...
}
标题 Html:{{itemCount | 异步}}
购物车服务:
export class ShoppingCartService {
....
public countBS: BehaviorSubject<number>;
public constructor() {
....
this.countBS = new BehaviorSubject<number>(0);
}
添加物品功能:
private SetCount(quantity: number): void {
this.count += quantity;
this.countBS.next(this.count);
this.storage.setItem('countCart', this.count.toString());
}
谢谢您的帮助
解决方案
推荐阅读
- java - 在 Spring 中使用类进行查询
- flutter - 如何在颤动中获得加速度计的更新频率?
- mysql - 无法启动 MariaDB 数据库服务器(MariaDB 服务器已关闭/超时)
- javascript - 如何选择元素的父元素而不是单击时具有 id/class 的父子元素?
- javascript - 寻找一种在网页上动态自动填充邮政编码输入的方法
- javascript - jquery 在现有表下追加表并链接到该行记录的 id
- sql - 如何编辑此 SQL 代码以过滤表中的数据?
- c++ - last input not working after exiting the while loop
- c++ - 为什么 afl-g++ 无法编译 ImageMagick?
- go - 在 FindAllString 正则表达式中排除重复项