Created
February 6, 2016 04:23
-
-
Save SirajGadhia/c7669de1465548809a5a to your computer and use it in GitHub Desktop.
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
//http://www.siraj360.com/ng2/ :: A single page application developed with Angular 2 (beta) and Bootstrap 4 (alpha). | |
import { Component, View, Input, Output, EventEmitter } from 'angular2/core'; | |
import { CORE_DIRECTIVES, NgClass } from 'angular2/common'; | |
@Component({ | |
selector: 'rating' | |
}) | |
@View({ | |
template: ` | |
<span tabindex="0"> | |
<template ngFor [ngForOf]="range" #index="index"> | |
<span class="sr-only">({{ index < rate ? '*' : ' ' }})</span> | |
<i (click)="update(index + 1)" | |
[ngClass]="index < rate ? 'fa fa-star fa-lg' : 'fa fa-star-o fa-lg'"> | |
</i> | |
</template> | |
</span> | |
`, | |
directives: [CORE_DIRECTIVES, NgClass] | |
}) | |
export class RatingComponent { | |
private range: Array<number> = [1, 2, 3, 4, 5]; | |
@Input() rate: number; | |
@Output('rating-change') ratingChange: EventEmitter<any> = new EventEmitter(); | |
update(value: number) { | |
this.rate = value; | |
this.ratingChange.next(value); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment