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