Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. import { Component } from '@angular/core';
  2.  
  3. @Component({
  4. selector: 'user',
  5. template: `<h1>Hello {{name}}</h1>
  6. <p><strong>Email:</strong> {{email}}</p>
  7. <p><strong>Address:</strong> {{address.street}} {{address.city}} {{address.state}}</p>
  8. <button (click)='toggleHobbies()'>{{showHobbies ? "Hide Hobbies" : "Show Hobbies"}}</button>
  9. <div *ngIf="showHobbies">
  10. <h3>Hobbies</h3>
  11. <ul>
  12. <li *ngFor="let hobby of hobbies">
  13. {{hobby}}
  14. </li>
  15. </ul>
  16. </div>
  17. `,
  18. })
  19. export class UserComponent {
  20. name: string;
  21. email: string;
  22. address: address;
  23. hobbies: string[];
  24. showHobbies: boolean;
  25.  
  26. constructor(){
  27. this.name = 'Hinni';
  28. this.email = 'hinni@gmail.com';
  29. this.address = {
  30. street: '12 Main st',
  31. city: 'Boston',
  32. state: 'MA'
  33. }
  34. this.hobbies = ['Music', 'Movies', 'Sports'];
  35. this.showHobbies = false;
  36. }
  37.  
  38. toggleHobbies(){
  39. if(this.showHobbies == true){
  40. this.showHobbies = false;
  41. } else {
  42. this.showHobbies = true;
  43. }
  44.  
  45. }
  46. }
  47.  
  48. interface address {
  49. street: string;
  50. city: string;
  51. state: string;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement