Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 48980

Route Guard - need help with calling component function

$
0
0

I try to implement route guard that need check is profile valid, but the function checkIsValid is not called

profile.guard.ts

import { Injectable } from '@angular/core';
import { CanDeactivate } from '@angular/router';
import { ProfilePage } from '../../pages/profile/profile.page';

@Injectable()
export class ProfileFormGuard implements CanDeactivate<ProfilePage> {
  constructor() {}
  canDeactivate(
    component: ProfilePage,
  ): Promise<boolean> {
    console.log('ProfileFormGuard'); // logged
    const isValid = component.checkIsValid();
    console.log('ProfileFormGuard isValid', isValid);  // not logged
    return new Promise(async (resolve, reject) => {
      resolve(isValid);
    });
  }
}

profile.page.ts

...
@Component({
  selector: 'app-profile',
  templateUrl: './profile.page.html',
  styleUrls: ['./profile.page.scss']
})
export class ProfilePage implements OnInit {
  public checkIsValid() {
    console.log('checkIsValid'); // not logged
    return true;
  }
...
}

what is wrong there, thank you

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 48980

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>