Поведение Тема не обновляется Asyn c Pipe - PullRequest
0 голосов
/ 19 марта 2020

Я пытаюсь использовать тему поведения для подачи асинхронной c трубы в мой html. Субъект работает с начальной загрузкой, но не будет регистрировать выброс при любой последующей попытке его обновления. То, что я не могу понять, это то, почему следующий в теме поведения не вызывает apiCall () из switchMap.

buy -plan.component. html

<div class="wrapper" *ngIf="buyPlan$ | async as buyPlan; else loading">
     <div class="desktop-container" *ngIf="deviceInfoService.isDesktopDevice; else mobileContainer">
         <app-buy-plans-desktop [buyPlan]="buyPlan"> </app-buy-plans-desktop>
     </div>
     <ng-template #mobileContainer>
         <app-buy-plans-mobile [buyPlan]="buyPlan"></app-buy-plans-mobile>
     </ng-template>
</div>

<ng-template #loading>
      <div class="spinner-wrapper" [ngClass]="{ 'sidenav-open': sharedService.isSidenavOpen$ | async }">
          <div class="spinner-mask"></div>
              <mat-spinner class="buy-plans-spinner" color="accent"></mat-spinner>
          </div>
</ng-template> 

buyplans.component.ts

export class BuyPlansComponent implements OnInit {
  buyPlanSub$ = new BehaviorSubject(null);
  buyPlan$ = new Observable<ICollectionDto | IErrorDto>();
  testSub$ = new Subject();

  title = '';
  creationDate = '';
  progressSpinnerMode = 'indeterminate';
  createDialogData: IModifyBuyPlanDialogVM = {
    title: 'Create Buy Plan',
    primaryAction: {
      buttonColor: 'accent',
      text: 'Create'
    }
  };

  constructor(
    private collectionService: CollectionService,
    private buyPlanService: BuyPlanService,
    public sharedService: SharedService,
    public deviceInfoService: DeviceInfoService
  ) {}

  ngOnInit() {
    this.buyPlan$ = this.buyPlanSub$.pipe(switchMap(e => this.apiCall(e)));

    // testSub$ is extraneous and just for debugging that I could get an emit out of the subscribe
    this.testSub$.subscribe(() => {
      console.log('Test Sub Hit'); //Reaches here
      this.buyPlanSub$.next({}); // Does not go to apiCall()
    });

    this.buyPlanSub$.next(null);
  }

  apiCall(id) {
    console.log('In API call');
    return this.collectionService.get(null, CollectionItemType.BuyPlan);
  }

  cancelBuyPlan(id: number) {}

  copyBuyPlan(id: number) {}

  deleteBuyPlan(id: number) {
    this.buyPlanService.delete(id).subscribe(response => {
      console.log(response);
      this.testSub$.next(response);
    });
  }

  openCreateBuyPlanDialog($event) {}
}
...