Q: How to fix Angular 7 Router Guard not working I am trying to write a router guard that checks if page terms have been accepted, if not, deny access. 
Here is the service:
@Injectable()
export class ItemService {
  public _itemsSource = new Subject<any | null>();
  itemsObservable = this._itemsSource.asObservable();


  constructor(
    public afs: AngularFirestore
  ) {
  }

  getItemSettings(){
   return  this.itemsObservable.pipe(
      first(),
      switchMap(item => {
       return this.afs.doc(`table-items/${item.id}`).valueChanges();
      })
    );

  }

and here is the guard:
@Injectable()
export class ItemEditGuard implements CanActivate {
  constructor(private itemService: ItemService, private router: Router,  private notify: NotifyService) {}
  canActivate(
    next: ActivatedRouteSnapshot,
    state: RouterStateSnapshot): Observable<boolean> | boolean {
      return this.itemService.getItemSettings().pipe(
        take(1),
        map((settings: any) =>  !!settings.terms),
        tap(acceptedTerms => {
          if (!acceptedTerms) {
            this.notify.update('<strong>Access Denied!</strong> You need to accept to collection terms to continue!', 'error');
            return;
          }
      })
    );
  }
}

The routermodule
 {
      path: 'edit',
      component: ItemEditComponent,
      canActivate: [ItemEditGuard],
      data: { title: 'Edit item', breadcrumb: 'EDIT' },
}

Unfortunately, this isn't working with no errors logged.
Btw, it's on a lazy loaded module.
What am I doing wrong? and how can I fix this?

A: 1_ tap() operator used to perform some action to received value before subscription is made, and map for manipulate, transform it.
2_ as you said you're trying to use this guard in lazyloaded module, so a canLoad interface need to be implemented and not canActive
@Injectable()
export class ItemEditGuard implements CanActivate {
    constructor(
        private itemService: ItemService,
        private router: Router,
        private notify: NotifyService
    ) { }
    canActivate(
        route: Route,
        segments: UrlSegment[]
    ): Observable<boolean> | boolean {
        return this.itemService.getItemSettings()
            .pipe(
                map((settings: any) => !!settings.terms),
                map(acceptedTerms => {
                    if (!acceptedTerms) {
                        this.notify.update('<strong>Access Denied!</strong> You need to accept to collection terms to continue!', 'error');
                    }
                    return acceptedTerms;
                })
            );
    }
}
you can read more about :


*

*
can load


*
first() vs take(1)


*
map()


*
tap()

