Last active
November 29, 2016 06:33
-
-
Save milad1367/c0f058e037a5ff3fe0b0e66210e6e218 to your computer and use it in GitHub Desktop.
ngoninit
This file contains 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
import { Component } from '@angular/core'; | |
import { RouterModule, Routes } from '@angular/router'; | |
import { Router } from '@angular/router'; | |
import {InfoComponent} from './info.component' | |
export class Hero { | |
name:string; | |
email:string; | |
} | |
@Component({ | |
selector: 'my-app', | |
template: ` | |
<div id="my-signin2" (data-onsuccess)="onSignIn"></div> | |
<router-outlet></router-outlet> | |
{{userDisplayName}} | |
` | |
}) | |
export class AppComponent { | |
heroes :Hero[] = [{name:'mm',email:'mmm'}] ; | |
hero:Hero = {name:'',email:''}; | |
userDisplayName = "empty"; | |
t = false; | |
constructor(private router: Router){ | |
console.log(this); | |
} | |
ngAfterViewInit() { | |
gapi.signin2.render('my-signin2', { | |
'onsuccess': param => this.onSignIn(param), | |
'scope': 'profile email', | |
'width': 240, | |
'height': 50, | |
'longtitle': true, | |
'theme': 'light' | |
}); | |
} | |
onSignIn(googleUser) { | |
var profile = googleUser.getBasicProfile(); | |
// console.log("ID: " + profile.getId()); // Don't send this directly to your server! | |
// console.log('Full Name: ' + profile.getName()); | |
// console.log('Given Name: ' + profile.getGivenName()); | |
// console.log('Family Name: ' + profile.getFamilyName()); | |
// console.log("Image URL: " + profile.getImageUrl()); | |
// console.log("Email: " + profile.getEmail()); | |
this.userDisplayName = profile.getName(); | |
}; | |
addHero(hero: Hero){ | |
if(hero.name){ | |
this.heroes.push(hero); | |
} | |
} | |
goHome() { | |
this.router.navigate(['login']); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment