I found a way to do this, but I have another problem look:
Initially I begin my menu so:
constructor(public events: Events, public platform: Platform, public statusBar: StatusBar, public splashScreen: SplashScreen, public app: App, public alertCtrl: AlertController, private service: Auth) {
this.initializeApp();
this.menu();
this.showHiddenMenu(); // tem que ficar abaixo se não fica indefinido em quantidade o menu
events.subscribe('user:authenticated', (isLoggedIn, profile)=> {
this.isLoggedIn = isLoggedIn;
this.profile = profile;
console.log(this.profile.profile_id);
})
}
}
menu() {
this.pages = [
{ title: 'Home', component: Home, profile: 1, hidden: this.esconde },
{ title: 'Meu Perfil', component: Home, profile: 1, hidden: this.esconde },
{ title: 'Minha Causa', component: ListCauses, profile: 3, hidden: this.esconde },
{ title: 'Causas Cidadãs', component: ListCausesCitizens, profile: 2, hidden: this.esconde },
{ title: 'Advogados', component: ListLawyers, profile: 3, hidden: this.esconde },
{ title: 'Legislação', component: Legislation, profile: 1, hidden: this.esconde },
{ title: 'Ajuda', component: Help, profile: 1, hidden: this.esconde },
{ title: 'Sair', component: null, profile: '', hidden: this.esconde }
];
this.activePage = this.pages[0];
}
the following step, I created a methodo for hide or show menu
showHiddenMenu() {
let myProfile= this.profile;
//let myProfile = 2;
for(let page of this.pages) {
if(myProfile == 1 && page.profile== 1 || page.profile== 2 || page.profile== 3 ) {
console.log('I adm and can see all');
}
if(myProfile == 2 && page.profile== 3) {
console.log('I'm user 2');
page.hidden= true;
}
if(myProfile == 3 && page.profile == 2) {
console.log('I am user 3');
page.hidden= true;
}
}
}
I my view I have
<ion-list>
<button menuClose ion-item *ngFor="let p of pages" [hidden]="p.hidden" [class.activeHighLight]="checkActive(p)" (click)="openPage(p)">
{{p.title}}
</button>
</ion-list>
My problem, how to get the profile after login in API that need TOKEN and insert in app.components ?