Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/430.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从具有角度模型的行为主体获取的Getter值_Javascript_Angular_Rxjs - Fatal编程技术网

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;
  }