Значение получателя от объекта поведения с моделью в угловых - PullRequest
0 голосов
/ 09 ноября 2019

Мой сервис

        **Assign to data:Group gives error in get function
        Observable<Group>' is missing the following properties from type** 
    import { Injectable } from '@angular/core';
    import { BehaviorSubject, Observable } from 'rxjs';
    import { Group } from "../models/group.model";

    @Injectable({
      providedIn: 'root'
    })
    export class GroupService {

      newGroup = new Group;
      private groupListSource = new BehaviorSubject<Group>(this.newGroup);
      public groupListValue: Observable<Group> = this.groupListSource.asObservable()

      constructor() { }

      set groupItems(**data: Group**) {
        this.groupListSource.next(Object.assign({}, data));
      }

      get groupItems() {
        return this.groupListValue;
      }

    }

Моя модель

    export class Group {
        groupId: string;
        groupName: string;
    }

1 Ответ

0 голосов
/ 11 ноября 2019

решил сам

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;
  }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...