Skip to content

Instantly share code, notes, and snippets.

@llucasshenrique
Last active October 19, 2017 05:21
Show Gist options
  • Save llucasshenrique/c4c6eb55552708c59a0f66862c65d56e to your computer and use it in GitHub Desktop.
Save llucasshenrique/c4c6eb55552708c59a0f66862c65d56e to your computer and use it in GitHub Desktop.
Multiple Profiles App
@Component({
templateUrl: 'app.html'
})
export class MyApp {
public activeProfile: Profile;
constructor(
private afAuth: AngularFireAuth,
private profileProvider: ProfileProvider,
) {
afAuth.auth.onAuthStateChanged( user => {
if (user) {
this.rootPage = 'TabsControllerPage',
this.profileList = this.profileProvider.getBy('account', user.uid),
console.log('user', user);
events.subscribe('profileChanged', profile => {
console.log('changed profile', profile)
this.activeProfile = profile;
})
this.selectProfile(this.afAuth.auth.currentUser.uid);
} else {
this.rootPage = 'BemVindoPage'
}
})
}
selectProfile(profileKey: string) {
this.profileProvider.selectActiveProfile(profileKey);
}
}
@Injectable()
export class ProfileProvider {
public activeProfile: Profile;
constructor(
private afoDB: AngularFireOfflineDatabase,
private events: Events) { }
selectActiveProfile(profileKey: string) {
this.activeProfile = this.getByKey(profileKey).value
this.events.publish('profileChanged', this.activeProfile)
}
getByKey(profileKey: string) {
return this.afoDB.object(`/profile/${profileKey}`);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment