I get the following error:
angular2.dev.js:23925 EXCEPTION: TypeError: Cannot read property 'Id' of null in [ {{ product.Id }} in ProductEditComponent@0 :68]
thrown using:
//Product-edit.component.ts: import {Component } from 'angular2/core'; import { IProduct } from './product' import { ProductService } from './product.service' import { RouteParams } from 'angular2/router'; @Component({ template:`<div class="wrapper wrapper-content animated fadeInRight ecommerce"> {{ product.Id }} </div>`, }) export class ProductEditComponent{ product: IProduct = null; errorMessage: string; constructor(private _routeParams: RouteParams, private _productService: ProductService){ } ngOnInit(): void { this._productService.getProduct(this._routeParams.get('id')) .subscribe( product => this.product = product, error => this.errorMessage = <any>error); } }
ProductService:
getProduct(id: string): Observable<IProduct> { return this._http.get(this._baseUrl + this._getProductUrl + '/' + id) .map((response: Response) => <IProduct>response.json()) .do(data => console.log("All: " + JSON.stringify(data))) .catch(this.handleError); }
The response from the server:
{"Id":"34d4efcy6","ExternalId":null,"UserId":"testing","ProductProvider":null,"Title":"Flaska vin","Desc":null,"MinDeliveryTime":null,"MaxDeliveryTime":null,"FreightCost":null,"Brand":null}
What have I messed up?
source share