angular - Angular:扩展具有多个孩子的服务
问题描述
从多个子项扩展服务会创建服务的新实例。我希望能够扩展一项服务,如果一个孩子的数据发生变化,另一个孩子也应该可以使用它。
我尝试过创建服务。我创建了两个模块,它们都在扩展服务。
@Injectable({
providedIn: 'root'
})
export class BaseService {
//Api stuff going on here
constructor(){
}
}
@Injectable({
providedIn: 'root'
})
export class AuthService extends BaseService {
//Login stuff going on there
constructor(){
super()
}
}
export class LoginPage extends AuthService {
//Handles login
constructor(){
super()
}
}
@Injectable({
providedIn: 'root'
})
export class UserService extends AuthService {
//User stuff going on here
constructor(){
super()
}
}
export class ProfilePage extends UserService {
//Handles user stuff
constructor(){
super()
}
}
//So LoginPage and UserService are both extending AuthService. For example
//setting a token from LoginPage ->AuthService should make the token available //in the UserService. But how it is now is that it creates multiple instances //of AuthService. Is this even possible to accomplish?
我想知道这是否可能。我知道注入服务的基本方法,但这更酷更实用。
解决方案
推荐阅读
- python - 根据索引张量从张量中提取子张量
- wordpress - 当我使用 get_categories 时 hide_empty = '0' 不起作用
- arrays - 如何在pyspark的列中找到列表的平均值?
- python - 迷宫寻路实现 (BFS) 未提供正确路径
- google-cloud-platform - 云任务截止时间超过 30 秒
- haskell - 列表中的坐标
- c# - Unity - 如何在不同场景中正确引用 GameManager
- c++ - 如何通过 tcp/ip 连接前端和后端?
- arrays - SWIFT:在一个控制器中更新一个数组,但在另一个控制器中使用更新后的数组
- sql - 根据先前查询的结果(输出)创建表