Skip to content

Commit 397e2f2

Browse files
committed
Module 6: Data Binding & Pipes completed.
1 parent 6a9c55d commit 397e2f2

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

APM/src/app/app.module.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
import { BrowserModule } from '@angular/platform-browser';
22
import { NgModule } from '@angular/core';
3+
import { FormsModule} from '@angular/forms';
34

45
import { AppComponent } from './app.component';
56
import { ProductListComponent } from './products/product-list.component';
67

78
@NgModule({
89
declarations: [
910
AppComponent,
10-
ProductListComponent
11+
ProductListComponent,
1112
],
1213
imports: [
13-
BrowserModule
14+
BrowserModule,
15+
FormsModule,
1416
],
1517
bootstrap: [AppComponent]
1618
})

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

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
<div class="row">
77
<div class="col-md-2">Filter by:</div>
88
<div class="dol-md-4">
9-
<input type="text" />
9+
<input type="text"
10+
[(ngModel)]='listFilter' />
1011
</div>
1112
</div>
1213
<div class="row">
1314
<div class="col-md-6">
14-
<h4>Filtered by: </h4>
15+
<h4>Filtered by: {{listFilter}} </h4>
1516
</div>
1617
</div>
1718
<div class="table-responsive">
@@ -20,8 +21,9 @@ <h4>Filtered by: </h4>
2021
<thead>
2122
<tr>
2223
<th>
23-
<button class="btn-primary">
24-
Show Image
24+
<button class="btn-primary"
25+
(click)="toggleImage()">
26+
{{showImage ? 'Hide' : 'Show'}} Image
2527
</button>
2628
</th>
2729
<th>Product</th>
@@ -33,11 +35,17 @@ <h4>Filtered by: </h4>
3335
</thead>
3436
<tbody>
3537
<tr *ngFor='let product of products'>
36-
<td></td>
38+
<td>
39+
<img *ngIf='showImage'
40+
[src]='product.imageUrl'
41+
[title]='product.productName'
42+
[style.width.px]='imageWidth'
43+
[style.margin.px]='imageMargin'>
44+
</td>
3745
<td>{{ product.productName }}</td>
38-
<td>{{ product.productCode }}</td>
46+
<td>{{ product.productCode | lowercase }}</td>
3947
<td>{{ product.releaseDate }}</td>
40-
<td>{{ product.price }}</td>
48+
<td>{{ product.price | currency:'USD':'symbol':'1.2-2' }}</td>
4149
<td>{{ product.starRating }}</td>
4250
</tr>
4351

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import { Component } from '@angular/core';
66
})
77
export class ProductListComponent {
88
pageTitle: string = 'Product List';
9+
imageWidth: number=50;
10+
imageMargin: number=2;
11+
showImage: boolean=false;
12+
listFilter: string='cart';
913
products: any[] = [
1014
{
1115
"productId": 1,
@@ -38,4 +42,9 @@ export class ProductListComponent {
3842
"imageUrl": "assets/images/hammer.png"
3943
},
4044
];
45+
46+
toggleImage(): void
47+
{
48+
this.showImage = !this.showImage;
49+
}
4150
}

0 commit comments

Comments
 (0)