Skip to content

Commit 1da0325

Browse files
author
Ian Ellis
committed
progress as far more on components
1 parent d025b56 commit 1da0325

File tree

5 files changed

+53
-9
lines changed

5 files changed

+53
-9
lines changed

APM - Start/app/app.module.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
1+
//this is how we import external modules
12
import { NgModule } from '@angular/core';
23
import { BrowserModule } from '@angular/platform-browser';
4+
import { FormsModule } from '@angular/forms';
35

6+
//this is how we import internal modules
47
import { AppComponent } from './app.component';
58
import { ProductListComponent } from './products/product-list.component';
69

10+
//this is how we declare which modules we would like to use from the above imported modules
711
@NgModule({
8-
imports: [ BrowserModule ],
12+
//imports is used for external/3rd party directives, components and pipes
13+
imports: [
14+
BrowserModule,
15+
FormsModule
16+
],
17+
//declarations is used for our directives, components and pipes
918
declarations: [
1019
AppComponent,
1120
ProductListComponent
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
thead {
2+
color: #337AB7;
3+
}

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

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,25 @@
66
<div class="row">
77
<div class="col-md-2">Filtered by:</div>
88
<div class="col-md-4">
9-
<input type="text" />
9+
<!-- 2 way data binding i.e. setting the listFilter property in product-list.component.ts to the value of the input -->
10+
<input type="text" [(ngModel)]="listFilter"/>
1011
</div>
1112
</div>
1213
<div class="row">
1314
<div class="col-md-6">
14-
<h3>Filtered by: </h3>
15+
<!-- displaying the value of listFilter which is set by the input above via 2 way data banding -->
16+
<h3>Filtered by: {{listFilter}}</h3>
1517
</div>
1618
</div>
1719
<div class="table-responsive">
1820
<table class="table" *ngIf="products && products.length">
1921
<thead>
2022
<tr>
2123
<th>
22-
<button class="btn btn-primary">Show Image</button>
24+
<button class="btn btn-primary"
25+
(click)="toggleImage()">
26+
{{showImage ? 'Hide' : 'Show'}} Image
27+
</button>
2328
</th>
2429
<th>Product</th>
2530
<th>Code</th>
@@ -30,11 +35,17 @@ <h3>Filtered by: </h3>
3035
</thead>
3136
<tbody>
3237
<tr *ngFor="let product of products">
33-
<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>
3445
<td>{{product.productName}}</td>
35-
<td>{{product.productCode}}</td>
46+
<td>{{product.productCode | lowercase}}</td>
3647
<td>{{product.releaseDate}}</td>
37-
<td>{{product.price}}</td>
48+
<td>{{product.price | currency:'USD':true:'1.2-2'}}</td>
3849
<td>{{product.starRating}}</td>
3950
</tr>
4051
</tbody>

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
import { Component } from '@angular/core';
2+
import { IProduct } from './product';
23

34
@Component({
45
selector: 'pm-products',
5-
templateUrl: 'app/products/product-list.component.html'
6+
templateUrl: 'app/products/product-list.component.html',
7+
styleUrls: ['app/products/product-list.component.css']
68
})
79
export class ProductListComponent {
810
pageTitle: string = 'Product List';
9-
products: any[] = [
11+
imageWidth: number = 50;
12+
imageMargin: number = 2;
13+
showImage: boolean = false;
14+
listFilter: string = 'cart';
15+
16+
products: IProduct[] = [
1017
{
1118
"productId": 1,
1219
"productName": "Leaf Rake",
@@ -58,4 +65,8 @@ export class ProductListComponent {
5865
"imageUrl": "http://openclipart.org/image/300px/svg_to_png/120337/xbox-controller_01.png"
5966
}
6067
];
68+
69+
toggleImage(): void {
70+
this.showImage = !this.showImage;
71+
}
6172
}

APM - Start/app/products/product.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export interface IProduct {
2+
productId: number,
3+
productName: string,
4+
productCode: string,
5+
releaseDate: string,
6+
description: string,
7+
price: number,
8+
starRating: number,
9+
imageUrl: string
10+
}

0 commit comments

Comments
 (0)