From b89e3aa31182b76b175f8ee1004d1e9ec635a763 Mon Sep 17 00:00:00 2001 From: Michael Hladky Date: Tue, 31 Jan 2017 00:34:38 +0100 Subject: [PATCH] fix(example): updated angular2 example --- .../common/star-rating/star-rating-struct.ts | 4 ++-- .../star-rating/star-rating.component.ts | 23 +++++++++++-------- .../app/component/start/start.component.html | 3 ++- .../app/component/start/start.component.ts | 9 +++++++- 4 files changed, 26 insertions(+), 13 deletions(-) diff --git a/examples/test/app/common/star-rating/star-rating-struct.ts b/examples/test/app/common/star-rating/star-rating-struct.ts index 7434a84..29e6639 100644 --- a/examples/test/app/common/star-rating/star-rating-struct.ts +++ b/examples/test/app/common/star-rating/star-rating-struct.ts @@ -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; } diff --git a/examples/test/app/common/star-rating/star-rating.component.ts b/examples/test/app/common/star-rating/star-rating.component.ts index e06dffe..11652a3 100644 --- a/examples/test/app/common/star-rating/star-rating.component.ts +++ b/examples/test/app/common/star-rating/star-rating.component.ts @@ -7,7 +7,7 @@ import { starRatingStarSpace, starRatingStarTypes, IStarRatingOnClickEvent, - IStarRatingOnUpdateEvent + IStarRatingOnRatingChangeEvent } from "./star-rating-struct"; import {StarRatingConfig} from "./star-rating-config"; @@ -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); } @@ -348,10 +348,10 @@ export class StarRatingComponent implements OnInit, OnChanges { //Output /////////////////////////////////////////////////////////////////////////////////////////// @Output() - onClick: EventEmitter; + onClick: EventEmitter = new EventEmitter(); @Output() - onUpdate: EventEmitter; + onRatingChange: EventEmitter = new EventEmitter(); //CTRL ONLY /////////////////////////////////////////////////////////////////////////////////////////// @@ -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; @@ -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; } @@ -441,6 +441,11 @@ export class StarRatingComponent implements OnInit, OnChanges { this.rating = rating; + let onClickEventObject:IStarRatingOnClickEvent = { + rating:this.rating + }; + this.onClick.emit(onClickEventObject); + } ngOnInit() { diff --git a/examples/test/app/component/start/start.component.html b/examples/test/app/component/start/start.component.html index 0701867..a255893 100644 --- a/examples/test/app/component/start/start.component.html +++ b/examples/test/app/component/start/start.component.html @@ -1,3 +1,4 @@

Start

- + + diff --git a/examples/test/app/component/start/start.component.ts b/examples/test/app/component/start/start.component.ts index 599cc0b..55dd8b2 100644 --- a/examples/test/app/component/start/start.component.ts +++ b/examples/test/app/component/start/start.component.ts @@ -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, @@ -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); } }