Skip to content

Commit

Permalink
fix(example): updated angular2 example
Browse files Browse the repository at this point in the history
  • Loading branch information
BioPhoton committed Jan 30, 2017
1 parent 94ad8b6 commit b89e3aa
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 13 deletions.
4 changes: 2 additions & 2 deletions examples/test/app/common/star-rating/star-rating-struct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ export interface IStarRatingCompBindings {
getColor?(rating: number, numOfStars: number, staticColor?: starRatingColors): starRatingColors;
//Outputs (& bindings)
onClick?: ($event: any) => IStarRatingOnClickEvent;
onUpdate?: ($event: any) => IStarRatingOnUpdateEvent;
onUpdate?: ($event: any) => IStarRatingOnRatingChangeEvent;
}

export interface IStarRatingOnClickEvent {
rating: number;
}

export interface IStarRatingOnUpdateEvent {
export interface IStarRatingOnRatingChangeEvent {
rating: number;
}
23 changes: 14 additions & 9 deletions examples/test/app/common/star-rating/star-rating.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
starRatingStarSpace,
starRatingStarTypes,
IStarRatingOnClickEvent,
IStarRatingOnUpdateEvent
IStarRatingOnRatingChangeEvent
} from "./star-rating-struct";
import {StarRatingConfig} from "./star-rating-config";

Expand Down Expand Up @@ -306,9 +306,9 @@ export class StarRatingComponent implements OnInit, OnChanges {
this.setColor();


//fire onUpdate event
let $event: IStarRatingOnUpdateEvent = {rating: this._rating};
//this.onUpdate.emit($event);
//fire onRatingChange event
let $event: IStarRatingOnRatingChangeEvent = {rating: this._rating};
this.onRatingChange.emit($event);
}


Expand Down Expand Up @@ -348,10 +348,10 @@ export class StarRatingComponent implements OnInit, OnChanges {
//Output
///////////////////////////////////////////////////////////////////////////////////////////
@Output()
onClick: EventEmitter<IStarRatingOnClickEvent>;
onClick: EventEmitter<IStarRatingOnClickEvent> = new EventEmitter<IStarRatingOnClickEvent>();

@Output()
onUpdate: EventEmitter<IStarRatingOnUpdateEvent>;
onRatingChange: EventEmitter<IStarRatingOnRatingChangeEvent> = new EventEmitter<IStarRatingOnRatingChangeEvent>();

//CTRL ONLY
///////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -369,7 +369,7 @@ export class StarRatingComponent implements OnInit, OnChanges {
halfStarVisible: boolean;

constructor(protected config: StarRatingConfig) {
console.log('config: ', config);

//set default ctrl props
this.classEmpty = config.classEmpty;
this.classHalf = config.classHalf;
Expand All @@ -379,11 +379,11 @@ export class StarRatingComponent implements OnInit, OnChanges {
this.pathFilled = config.svgPathFilled;

//set default Component Inputs
if ('getColor' in config) {
if ('getColor' in config && typeof config.getColor === "function") {
this.getColor = config.getColor;
}

if ('getHalfStarVisible' in config) {
if ('getHalfStarVisible' in config && typeof config.getHalfStarVisible === "function") {
this.getHalfStarVisible = config.getHalfStarVisible;
}

Expand Down Expand Up @@ -441,6 +441,11 @@ export class StarRatingComponent implements OnInit, OnChanges {

this.rating = rating;

let onClickEventObject:IStarRatingOnClickEvent = {
rating:this.rating
};
this.onClick.emit(onClickEventObject);

}

ngOnInit() {
Expand Down
3 changes: 2 additions & 1 deletion examples/test/app/component/start/start.component.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<h1>Start</h1>
<star-rating-comp></star-rating-comp>
<star-rating-comp (onClick)="onClick($event)" (onRatingChange)="onRatingChange($event)"></star-rating-comp>

<dynamic-form [questions]="questions"></dynamic-form>
9 changes: 8 additions & 1 deletion examples/test/app/component/start/start.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Component, OnInit, Input, Output, OnChanges, EventEmitter } from '@angular/core';
import {ItemService} from "./item.service";
import {IStarRatingOnClickEvent} from "angular-star-rating/src/star-rating-struct";

@Component({
moduleId: module.id,
Expand All @@ -15,10 +16,16 @@ export class StartComponent implements OnInit, OnChanges {
}

ngOnInit() {

}

ngOnChanges() {
}

onClick($event:IStarRatingOnClickEvent) {
console.log('onClick $event', $event);
}

onRatingChange($event:IStarRatingOnClickEvent) {
console.log('onRatingChange $event', $event);
}
}

0 comments on commit b89e3aa

Please # to comment.