Skip to content

Commit 54154aa

Browse files
committed
Fix HttpClient sample
1 parent f09d272 commit 54154aa

File tree

3 files changed

+21
-27
lines changed

3 files changed

+21
-27
lines changed

samples/data/product-data.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export class ProductData implements InMemoryDbService {
33
createDb() {
44
let products = [
55
{
6-
"ProductID": 1,
6+
"id": 1,
77
"ProductName": "Chai",
88
"DealerName": "A",
99
"CategoryName": "Beverages",
@@ -12,7 +12,7 @@ export class ProductData implements InMemoryDbService {
1212
"Inventory": ""
1313
},
1414
{
15-
"ProductID": 2,
15+
"id": 2,
1616
"ProductName": "Chang",
1717
"DealerName": "B",
1818
"CategoryName": "Beverages",
@@ -22,7 +22,7 @@ export class ProductData implements InMemoryDbService {
2222
},
2323
{
2424

25-
"ProductID": 3,
25+
"id": 3,
2626
"ProductName": "Aniseed Syrup",
2727
"DealerName": "C",
2828
"CategoryName": "Condiments",
@@ -31,7 +31,7 @@ export class ProductData implements InMemoryDbService {
3131
"Inventory": ""
3232
},
3333
{
34-
"ProductID": 4,
34+
"id": 4,
3535
"ProductName": "Chef Anton\u0027s Cajun Seasoning",
3636
"DealerName": "D",
3737
"CategoryName": "Condiments",
@@ -41,7 +41,7 @@ export class ProductData implements InMemoryDbService {
4141
},
4242
{
4343

44-
"ProductID": 5,
44+
"id": 5,
4545
"ProductName": "Chef Anton\u0027s Gumbo Mix",
4646
"DealerName": "E",
4747
"CategoryName": "Condiments",
@@ -51,7 +51,7 @@ export class ProductData implements InMemoryDbService {
5151
},
5252
{
5353

54-
"ProductID": 6,
54+
"id": 6,
5555
"ProductName": "Grandma\u0027s Boysenberry Spread",
5656
"DealerName": "F",
5757
"CategoryName": "Condiments",
@@ -61,7 +61,7 @@ export class ProductData implements InMemoryDbService {
6161
},
6262
{
6363

64-
"ProductID": 7,
64+
"id": 7,
6565
"ProductName": "Uncle Bob\u0027s Organic Dried Pears",
6666
"DealerName": "G",
6767
"CategoryName": "Produce",
@@ -71,7 +71,7 @@ export class ProductData implements InMemoryDbService {
7171
},
7272
{
7373

74-
"ProductID": 8,
74+
"id": 8,
7575
"ProductName": "Northwoods Cranberry Sauce",
7676
"DealerName": "H",
7777
"CategoryName": "Condiments",
@@ -81,7 +81,7 @@ export class ProductData implements InMemoryDbService {
8181
},
8282
{
8383

84-
"ProductID": 9,
84+
"id": 9,
8585
"ProductName": "Mishi Kobe Niku",
8686
"DealerName": "I",
8787
"CategoryName": "Meat/Poultry",
@@ -91,7 +91,7 @@ export class ProductData implements InMemoryDbService {
9191
},
9292
{
9393

94-
"ProductID": 10,
94+
"id": 10,
9595
"ProductName": "Ikura",
9696
"DealerName": "J",
9797
"CategoryName": "Seafood",
@@ -101,7 +101,7 @@ export class ProductData implements InMemoryDbService {
101101
},
102102
{
103103

104-
"ProductID": 11,
104+
"id": 11,
105105
"ProductName": "Queso Cabrales",
106106
"DealerName": "K",
107107
"CategoryName": "Dairy Products",
@@ -111,7 +111,7 @@ export class ProductData implements InMemoryDbService {
111111
},
112112
{
113113

114-
"ProductID": 12,
114+
"id": 12,
115115
"ProductName": "Queso Manchego La Pastora",
116116
"DealerName": "J",
117117
"CategoryName": "Dairy Products",
@@ -121,7 +121,7 @@ export class ProductData implements InMemoryDbService {
121121
},
122122
{
123123

124-
"ProductID": 13,
124+
"id": 13,
125125
"ProductName": "Konbu",
126126
"DealerName": "K",
127127
"CategoryName": "Seafood",
@@ -131,7 +131,7 @@ export class ProductData implements InMemoryDbService {
131131
},
132132
{
133133

134-
"ProductID": 14,
134+
"id": 14,
135135
"ProductName": "Tofu",
136136
"DealerName": "L",
137137
"CategoryName": "Produce",
@@ -141,7 +141,7 @@ export class ProductData implements InMemoryDbService {
141141
},
142142
{
143143

144-
"ProductID": 15,
144+
"id": 15,
145145
"ProductName": "Genen Shouyu",
146146
"DealerName": "M",
147147
"CategoryName": "Condiments",

samples/igGrid-HTTPClient/app.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,12 @@ export class ProductService {
2121
return people$;
2222
}
2323

24-
addProduct(ProductID, ProductName, DealerName, CategoryName, InStock): Observable<Product> {
25-
let newProduct: Product = { ProductID, ProductName, DealerName, CategoryName, InStock } as Product;
24+
addProduct(id, ProductName, DealerName, CategoryName, InStock): Observable<Product> {
25+
let newProduct: Product = { id, ProductName, DealerName, CategoryName, InStock } as Product;
2626
let headers = new HttpHeaders({ 'Content-Type': 'application/json', 'Authorization': 'my-auth-token' });
2727
return this.http.post<Product>("app/products", newProduct, {"headers": headers});
2828
}
2929

30-
private handleError (error: any) {
31-
let errMsg = (error.message) ? error.message :
32-
error.status ? `${error.status} - ${error.statusText}` : 'Server error';
33-
console.error(errMsg); // log to console instead
34-
return Observable.throw(errMsg);
35-
}
3630
}
3731

3832
@Component({
@@ -63,9 +57,9 @@ export class AppComponent {
6357
width: "100%",
6458
height: "400px",
6559
autoGenerateColumns: false,
66-
primaryKey: "ProductID",
60+
primaryKey: "id",
6761
columns: [
68-
{ key: "ProductID", headerText: "Product ID", width: "15%", dataType: "number" },
62+
{ key: "id", headerText: "Product ID", width: "15%", dataType: "number" },
6963
{ key: "ProductName", headerText: "Name", width: "35%", dataType: "string" },
7064
{ key: "DealerName", headerText: "Dealer Name", width: "15%", dataType: "string" },
7165
{ key: "CategoryName", headerText: "CategoryName", width: "25%", dataType: "string" },
@@ -85,7 +79,7 @@ export class AppComponent {
8579
addProduct(newProductName, newDealerName, newCategoryName, newInStock) {
8680
this.newId++;
8781
this.productService.addProduct(this.newId, newProductName, newDealerName, newCategoryName, newInStock)
88-
.subscribe(product => this.products = []);
82+
.subscribe(product => this.products.push(product));
8983
}
9084
}
9185

samples/igGrid-HTTPClient/product.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export interface Product {
2-
ProductID: number;
2+
id: number;
33
ProductName: string;
44
DealerName: string;
55
CategoryName:string;

0 commit comments

Comments
 (0)