【发布时间】:2018-09-12 07:42:43
【问题描述】:
我正在使用 Angular4 应用程序。在此我试图显示它显示为 [object object] 的 API 响应。
import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
import { HttpClient } from '@angular/common/http';
import { Data } from '@angular/router';
@Injectable()
export class CartdataService {
public i_product_Path = new BehaviorSubject<any>('');
i_cast_Product_Path = this.i_product_Path.asObservable();
current_product :any;
constructor(private http: HttpClient) { }
get_Product_Path(pName: string) {
this.current_product = pName.trim();
this.http.get(`http://localhost:abc/api/data/GetImage/?imageName=${this.current_product}`);
}
}
我在这里调用 API。
这是我的模型文件。
export interface Images {
big_Images: BImage[];
small_Images: Simage[];
selected_Product_Images: SelectedImage[]
}
export interface BImage {
big_Images: string;
}
export interface Simage {
small_Images: string;
}
export interface SelectedImage {
selected_Product_Image: string;
}
这是我的组件
import { Component } from '@angular/core';
import { CartdataService } from './cartdata.service';
import { Images } from './model';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
constructor(private CartdataService: CartdataService) {}
images : Images;
ngOnInit() {
this.CartdataService.i_cast_Product_Path.subscribe( (response : Images ) =>
{ this.images = response; });
}
}
在这里我得到 API 响应,我想要做的是我需要在单独的标签中显示所有 API 值。
<span >
{{images}}
</span>
通过使用上面的代码,我得到了 [object object] 的输出。
【问题讨论】:
-
你可以使用
ngFor然后像this S.O post一样绑定到图片src -
我试过了,但对我不起作用
-
你能展示一下你到目前为止所做的尝试吗?
标签: angular