Last active
October 19, 2017 05:21
-
-
Save llucasshenrique/c4c6eb55552708c59a0f66862c65d56e to your computer and use it in GitHub Desktop.
Multiple Profiles App
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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