1
1
import { Component , OnInit } from '@angular/core'
2
2
import { IProduct } from './product'
3
+ import { ProductService } from './product.service'
3
4
@Component ( {
4
5
selector :'pm-products' ,
5
6
moduleId :module . id , //use for component relative path
6
- templateUrl :'./ product-list.component.html' ,
7
- styleUrls :[ './ product-list.component.css' ]
7
+ templateUrl :'product-list.component.html' ,
8
+ styleUrls :[ 'product-list.component.css' ]
8
9
} )
9
10
10
11
export class ProductListComponent implements OnInit {
@@ -24,67 +25,21 @@ export class ProductListComponent implements OnInit{
24
25
imageWidth :number = 50 ;
25
26
imageMargin :number = 2 ;
26
27
showImage :boolean = false ;
27
- listFilter :string = 'cart' ;
28
- products :IProduct [ ] = [
29
- {
30
- "productId" : 1 ,
31
- "productName" : "Leaf Rake" ,
32
- "productCode" : "GDN-0011" ,
33
- "releaseDate" : "March 19, 2016" ,
34
- "description" : "Leaf rake with 48-inch wooden handle." ,
35
- "price" : 19.95 ,
36
- "starRating" : 3.2 ,
37
- "imageUrl" : "http://openclipart.org/image/300px/svg_to_png/26215/Anonymous_Leaf_Rake.png"
38
- } ,
39
- {
40
- "productId" : 2 ,
41
- "productName" : "Garden Cart" ,
42
- "productCode" : "GDN-0023" ,
43
- "releaseDate" : "March 18, 2016" ,
44
- "description" : "15 gallon capacity rolling garden cart" ,
45
- "price" : 32.99 ,
46
- "starRating" : 4.2 ,
47
- "imageUrl" : "http://openclipart.org/image/300px/svg_to_png/58471/garden_cart.png"
48
- } ,
49
- {
50
- "productId" : 5 ,
51
- "productName" : "Hammer" ,
52
- "productCode" : "TBX-0048" ,
53
- "releaseDate" : "May 21, 2016" ,
54
- "description" : "Curved claw steel hammer" ,
55
- "price" : 8.9 ,
56
- "starRating" : 4.8 ,
57
- "imageUrl" : "http://openclipart.org/image/300px/svg_to_png/73/rejon_Hammer.png"
58
- } ,
59
- {
60
- "productId" : 8 ,
61
- "productName" : "Saw" ,
62
- "productCode" : "TBX-0022" ,
63
- "releaseDate" : "May 15, 2016" ,
64
- "description" : "15-inch steel blade hand saw" ,
65
- "price" : 11.55 ,
66
- "starRating" : 3.7 ,
67
- "imageUrl" : "http://openclipart.org/image/300px/svg_to_png/27070/egore911_saw.png"
68
- } ,
69
- {
70
- "productId" : 10 ,
71
- "productName" : "Video Game Controller" ,
72
- "productCode" : "GMG-0042" ,
73
- "releaseDate" : "October 15, 2015" ,
74
- "description" : "Standard two-button video game controller" ,
75
- "price" : 35.95 ,
76
- "starRating" : 4.6 ,
77
- "imageUrl" : "http://openclipart.org/image/300px/svg_to_png/120337/xbox-controller_01.png"
78
- }
79
- ] ;
80
-
28
+ listFilter :string ;
29
+ products :IProduct [ ] = [ ] ;
30
+ errorMessage :string ;
31
+ constructor ( private _productService : ProductService ) {
32
+
33
+ }
81
34
toggleImage ( ) : void
82
35
{
83
36
this . showImage = ! this . showImage ;
84
37
}
85
38
86
39
ngOnInit ( ) :void {
87
- console . log ( "init" )
40
+ this . _productService . getProducts ( )
41
+ . subscribe ( products => this . products = products ,
42
+ error => this . errorMessage = < any > error ) ;
88
43
}
89
44
90
45
@@ -96,4 +51,6 @@ onRatingClicked(message:string): void {
96
51
97
52
98
53
54
+
55
+
99
56
}
0 commit comments