Javascript 从具有角度模型的行为主体获取的Getter值
我的服务Javascript 从具有角度模型的行为主体获取的Getter值,javascript,angular,rxjs,Javascript,Angular,Rxjs,我的服务 **Assign to data:Group gives error in get function Observable<Group>' is missing the following properties from type** 解决了我自己的问题 newGroup = new Group(); private groupListSource = new BehaviorSubject<Group>(this.new
**Assign to data:Group gives error in get function
Observable<Group>' is missing the following properties from type**
解决了我自己的问题
newGroup = new Group();
private groupListSource = new BehaviorSubject<Group>(this.newGroup);
public groupListValue: Observable<Group> = this.groupListSource.asObservable()
constructor(private storageService: StorageService) { }
groupItems(data: Group) {
this.storageService.setLocalStore("groupList", data)
this.groupListSource.next(Object.assign({}, data));
}
get groupList() {
return this.groupListSource.value;
}
newGroup=newGroup();
private groupListSource=新行为主体(this.newGroup);
publicGroupListValue:Observable=this.groupListSource.asObservable()
构造函数(私有存储服务:存储服务){}
groupItems(数据:组){
this.storageService.setLocalStore(“groupList”,数据)
this.groupListSource.next(Object.assign({},data));
}
获取组列表(){
返回此.groupListSource.value;
}
changing data:Group=>data:any解决了我的错误,但需要正确的代码结构,感谢您在初始化newGroup
属性时忘记了括号,它应该是newGroup=newGroup()代码>
export class Group {
groupId: string;
groupName: string;
}
newGroup = new Group();
private groupListSource = new BehaviorSubject<Group>(this.newGroup);
public groupListValue: Observable<Group> = this.groupListSource.asObservable()
constructor(private storageService: StorageService) { }
groupItems(data: Group) {
this.storageService.setLocalStore("groupList", data)
this.groupListSource.next(Object.assign({}, data));
}
get groupList() {
return this.groupListSource.value;
}