0

I have a that code:

enum URLs {
  'STORY_BUILDER' = 'story-builder',
  'IB_VIEW' = 'ib-view',
}

defaultGroupStoryRequest$ = new ReplaySubject<boolean>();
defaultGroupIbViewRequest$ = new ReplaySubject<boolean>();



const invalidRequest = R.pathOr(
  false,
  ['extras', 'state', 'invalidRequest'],
  navigation,
);

if (invalidRequest) {
  this.router.events
    .pipe(
      filter((e) => e instanceof NavigationEnd),
      pairwise(),
    )
    .subscribe((e) => {
      const parts = (e[0] as NavigationEnd).url.split('/');
      const previousPage = parts[parts.length - 1];
      this.defaultGroupIbViewRequest$.next(previousPage === URLs.IB_VIEW);
      this.defaultGroupStoryRequest$.next(previousPage === URLs.STORY_BUILDER);
    });
}

And in template:

<shared-overlay [isVisible]="defaultGroupStoryRequest$ | async">
<ng-template>
<shared-confirm
  type="warning"
  question="Generating Story for the default group is not allowed."
  label="Please select different group."
  acceptText="Ok"
  acceptButtonStyle="btn-danger-outline"
  [showDeclineButton]="false"
  (accept)="defaultGroupStoryRequest$.next(false)"
>
</shared-confirm>

Subscribe is executing but i can't send value using next() method to show popup. Why my next() method don't execute? I want get previous page, and compare with value from enum, and after display popup on the screen.

  • Have you verified `previousPage` is the correct value you want to compare against? I suspect your comparisons are always returning `false`, which would mean your modal would never show. – BizzyBob Apr 01 '21 at 15:28
  • After investigation: yes, of course, I do console.log before a next() method and previousPage have a value from the enum. Condition is good. This is interesting because when I put next() method outside subscribe it is working, but when I put this inside subscribe next() working too, I subscribe this stream and value is on the stream, but in html template popup is not visible. – Michał Borzęcki Apr 01 '21 at 16:29
  • So, in the template, if you do: `[isVisible]="true"` does it work? If not, at least you know your where your problem is :-) – BizzyBob Apr 01 '21 at 16:31
  • I have changeDetectionStrategy.onPush – Michał Borzęcki Apr 01 '21 at 16:35
  • I'm suggesting to place static value as a test to see if modal displays when you know the value is 'true'. I don't think it should matter if you use onPush strategy or not. – BizzyBob Apr 01 '21 at 16:38
  • It seems like maybe the problem is not the replay subject inside subscribe, but rather the template / css or something on that side. – BizzyBob Apr 01 '21 at 16:39

0 Answers0