Created
June 26, 2016 00:55
-
-
Save linxlad/fe5e07f0987d3a2a12764e786c498b68 to your computer and use it in GitHub Desktop.
Angular 2 Twitter heart like icon component.
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, Input, Output, EventEmitter} from 'angular2/core' | |
/** | |
* <like [totalLikes]="post.totalLikes" [iLike]="post.iLike" (change)="oniLikeChange($event)"></like> | |
*/ | |
@Component({ | |
selector: 'like', | |
template: ` | |
<li | |
class="glyphicon glyphicon-heart" | |
[class.highlighted]="iLike" | |
(click)="onClick()" | |
> | |
</li> | |
`, | |
styles: [` | |
.glyphicon-heart { | |
color: #ccc; | |
font-size: 64px; | |
cursor: pointer; | |
} | |
.highlighted { | |
color: deeppink; | |
} | |
`] | |
}) | |
export class LikeComponent { | |
@Input() totalLikes = 0; | |
@Input() iLike = false; | |
@Output() change = new EventEmitter(); | |
onClick() { | |
this.iLike = !this.iLike; | |
this.totalLikes += this.iLike ? 1 : -1; | |
this.change.emit({newValue: this.iLike, newTotal: this.totalLikes}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment