我正在使用API连接我的应用。每当我发布一个帖子请求时,我都会得到一个看起来像这样的json
{
"output": {
"text": {
"values": [
"Sure ! What kind of mouse would you like"
],
"selection_policy": "sequential"
},
"cards": [
{
"Mouse_Type": "Wireless"
},
{
"Mouse_Type": "Optical"
}
]
}
}
在我的html中我创建了这个:
<ul class="cards-options">
<li *ngFor="let options of listOptions" >
<span class="card">
<p>{{options.Mouse_Type }}</p>
</span>
</li>
</ul>
我的组件是这样的:
export class InputFieldComponent implements OnInit {
value = '';
listOptions = '';
public context :object;
constructor(private http : Http) { }
ngOnInit() {
}
onEnter(value: string) {
this.http.post('/APIconversation', {"input":value })
.map(response=>response.json())
.subscribe(
data => {
this.listOptions = data.output.cards;
console.log(this.listOptions);
}
)
}
每当我检查* ngFor的元素时,我都会发现:
bindings = {&#34; ng-reflect-ng-for-of&#34;:&#34; [object Object],[object 对象&#34; }
如何访问对象中的字符串?我用另一个API做了同样的事情并且它正在工作。 谢谢你的帮助。