Skip to content

Commit c0f4aa3

Browse files
committed
As of Module 7
1 parent 2b10544 commit c0f4aa3

File tree

7 files changed

+37
-4
lines changed

7 files changed

+37
-4
lines changed

APM-CLI-Final/src/app/app.module.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ import { FormsModule } from '@angular/forms';
55
import { AppComponent } from './app.component';
66
import { ProductListComponent } from './products/product-list.component';
77
import { ConvertToSpacesPipe } from './shared/convert-to-spaces.pipe';
8+
import { StarComponent } from './shared/star.component';
89

910
@NgModule({
1011
declarations: [
1112
AppComponent,
1213
ProductListComponent,
13-
ConvertToSpacesPipe
14+
ConvertToSpacesPipe,
15+
StarComponent
1416
],
1517
imports: [
1618
BrowserModule,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
thead {
2-
color: #337AB7
2+
color: #337AB7;
33
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ <h3>Filtered by: {{listFilter}} </h3>
4545
<td>{{ product.productCode | lowercase | convertToSpaces: '-' }}</td>
4646
<td>{{ product.releaseDate }}</td>
4747
<td>{{ product.price | currency:'USD':true:'1.2-2'}}</td>
48-
<td>{{ product.starRating }}</td>
48+
<td>
49+
<pm-star [rating]='product.starRating'
50+
(ratingClicked)='onRatingClicked($event)'>
51+
</pm-star>
52+
</td>
4953
</tr>
5054
</tbody>
5155
</table>

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ export class ProductListComponent implements OnInit {
5050
this.listFilter = 'cart';
5151
}
5252

53+
onRatingClicked(message: string): void {
54+
this.pageTitle = 'Product List: ' + message;
55+
}
56+
5357
performFilter(filterBy: string): IProduct[] {
5458
filterBy = filterBy.toLocaleLowerCase();
5559
return this.products.filter((product: IProduct) =>

APM-CLI-Final/src/app/products/product.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ export interface IProduct {
88
starRating: number;
99
imageUrl: string;
1010
}
11+

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<div class="crop"
22
[style.width.px]="starWidth"
3-
[title]="rating">
3+
[title]="rating"
4+
(click)="onClick()">
45
<div style="width: 86px">
56
<span class="glyphicon glyphicon-star"></span>
67
<span class="glyphicon glyphicon-star"></span>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { Component, OnChanges, Input, EventEmitter, Output } from '@angular/core';
2+
3+
@Component({
4+
selector: 'pm-star',
5+
templateUrl: './star.component.html',
6+
styleUrls: ['./star.component.css']
7+
})
8+
export class StarComponent implements OnChanges {
9+
@Input() rating: number;
10+
starWidth: number;
11+
@Output() ratingClicked: EventEmitter<string> =
12+
new EventEmitter<string>();
13+
14+
ngOnChanges(): void {
15+
this.starWidth = this.rating * 86 / 5;
16+
}
17+
18+
onClick(): void {
19+
this.ratingClicked.emit(`The rating ${this.rating} was clicked!`);
20+
}
21+
}

0 commit comments

Comments
 (0)