Skip to content

Use of Feature Toggles

Roberto Mena edited this page Mar 8, 2021 · 1 revision

The following instructions show an example about how to use Features Toggles in the UI project. Doing it so, we avoid the issue of broken tests

First, create a var of type subscribe

  isEnableToggleSubscription: Subscription;

Then, to detect if isFeatureToggleActivated you can do use this method

  isFeatureToggleActivated() {
    return this.featureManagerService.isToggleEnabledForUser('ui-list-technologies').pipe(
      map((enabled) => {
        return enabled === true ? true : false;
      })
    );
  }

And in the ngOnInit() you can do add the isFeatureToggleActivate and assign the isFeatureToggleActivate in isEnableToggleSubscription

  ngOnInit(): void {
    this.isEnableToggleSubscription = this.isFeatureToggleActivated().subscribe((flag) => {
      this.isUserRoleToggleOn = flag;
      console.log('in subscription', this.isUserRoleToggleOn);
    });

To finish is important unsubscribe the isEnableToggleSubscription

  ngOnDestroy() {
    this.isEnableToggleSubscription.unsubscribe();
  }
Clone this wiki locally