Skip to content

Commit 79921b9

Browse files
committed
Modified the Star component to generate output events.
1 parent b20fa4d commit 79921b9

File tree

5 files changed

+19
-6
lines changed

5 files changed

+19
-6
lines changed

APM - Final/app/products/product-list.component.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ <h3>Filtered by: {{listFilter}} </h3>
5151
<td>{{ product.productCode }}</td>
5252
<td>{{ product.releaseDate }}</td>
5353
<td>{{ product.price | currency:'USD':true }}</td>
54-
<td><in-star [rating]='product.starRating'></in-star></td>
54+
<td><in-star [rating]='product.starRating'
55+
(ratingClicked)='onRatingClicked($event)'></in-star></td>
5556
</tr>
5657
</tbody>
5758
</table>

APM - Final/app/products/product-list.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export class ProductListComponent implements OnInit {
3939
this.showImage = !this.showImage;
4040
}
4141

42-
onFilterChanged(filter: string) {
43-
this.listFilter = filter;
42+
onRatingClicked(message: string): void {
43+
this.pageTitle = 'Product List: ' + message;
4444
}
4545
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
.crop {
22
overflow: hidden;
33
}
4+
5+
span {
6+
cursor: pointer;
7+
}

APM - Final/app/shared/star.component.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
<div class="crop" [style.width.px]="starWidth">
1+
<div class="crop"
2+
[style.width.px]="starWidth"
3+
[title]='rating'
4+
(click)='onClick()'>
25
<div style="width: 86px">
36
<span class="glyphicon glyphicon-star"></span>
47
<span class="glyphicon glyphicon-star"></span>
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, Input, OnChanges } from 'angular2/core';
1+
import { Component, OnChanges, Input, Output, EventEmitter } from 'angular2/core';
22

33
@Component({
44
selector: 'in-star',
@@ -8,10 +8,15 @@ import { Component, Input, OnChanges } from 'angular2/core';
88
export class StarComponent implements OnChanges {
99
@Input() rating: number;
1010
starWidth: number;
11+
@Output() ratingClicked: EventEmitter<string> = new EventEmitter<string>();
1112

1213
ngOnChanges() {
1314
// Convert x out of 5 starts
1415
// to y out of 86px width
1516
this.starWidth = this.rating * 86/5;
16-
}
17+
}
18+
19+
onClick() {
20+
this.ratingClicked.emit(`The rating ${this.rating} was clicked!`);
21+
}
1722
}

0 commit comments

Comments
 (0)