Advertisement
Guest User

Untitled

a guest
Jun 25th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. import {Component, Input, Output, EventEmitter} from 'angular2/core'
  2.  
  3. /**
  4. * <like [totalLikes]="post.totalLikes" [iLike]="post.iLike" (change)="oniLikeChange($event)"></like>
  5. */
  6. @Component({
  7. selector: 'like',
  8. template: `
  9. <li
  10. class="glyphicon glyphicon-heart"
  11. [class.highlighted]="iLike"
  12. (click)="onClick()"
  13. >
  14. </li>
  15. `,
  16. styles: [`
  17. .glyphicon-heart {
  18. color: #ccc;
  19. font-size: 64px;
  20. cursor: pointer;
  21. }
  22. .highlighted {
  23. color: deeppink;
  24. }
  25. `]
  26. })
  27. export class LikeComponent {
  28. @Input() totalLikes = 0;
  29. @Input() iLike = false;
  30.  
  31. @Output() change = new EventEmitter();
  32.  
  33. onClick() {
  34. this.iLike = !this.iLike;
  35. this.totalLikes += this.iLike ? 1 : -1;
  36. this.change.emit({newValue: this.iLike, newTotal: this.totalLikes});
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement