【发布时间】:2018-02-06 11:32:33
【问题描述】:
在我的项目中,我有点击特定产品的功能,我想显示产品的特定细节,这里我将product: Object = []; 作为对象。在我的构造函数中
constructor( private _productService: UserService,
private _router: Router,
private _avRoute: ActivatedRoute,
private _actRouter: ActivatedRoute) {
if (this._avRoute.snapshot.params["id"]) {
this.Productid = parseInt(this._avRoute.snapshot.params["id"]);
console.log(this.Productid);
}
else {
}
}
我在ngOninit() 中获得特定产品的 id
ngOnInit() {
if (this.Productid > 0) {
this._productService.productDetail(this.Productid)
.subscribe( data => { this.product = data },
error => {
debugger;
this.errorMessage = error;
}
)
}
所以我的问题是,当我与我的 html 控件绑定时,
<div id="mainImage">
<img [src]="data.ProductImage" alt="" class="img-responsive">
</div>
<div class="box">
<h1 class="text-center" >{{data.ProductName}}</h1>
<p class="goToDescription"><a href="#details" class="scroll-to" >{{data.ProductShortDesc}}</a>
</div>
当我与此绑定时,会出现Cannot read property 'ProductImage' of undefined
at Object.eval 之类的错误
我参考这个网站来查询但不工作Click here
【问题讨论】:
-
html控件中的data.productImage应该是product.productImage。
-
@NiralMunjariya 我像你说的那样使用过,但没有用。
-
@Günter Zöchbauer 请帮助我会一直尝试。
-
您是否控制台记录了您从服务中获取的数据?
-
@NiralMunjariya ya do console.log 我会得到 ,Array(1) 0 : {$id: "1", ProductId: 4, ProductName: "T-Shirt", ProductPrice: 45, ProductCartDesc :“这是男士购物”,…} 长度:1
标签: angular