在我的项目中,我使用的是 Angular 2,我的编码如下:
this.http.get('http://localhost:8000/json')
.map(response => response.json())
.subscribe(data =>{ this.result = data });
并且 Object(this.result) 被加载到智能表中。它工作正常,但我想在智能表上方的文本框中显示结果中的名称。我编码如下:
<input type="text" [(ngModel)]="result.Name">
<br/><ng2-smart-table [settings]="settings" [source]="source"></ng2-smart-table>
但这不起作用,有什么可能的解决方案吗?
声明一个模型变量
名称:字符串;
然后
this.http.get('http://localhost:8000/json')
.map(response => response.json())
.subscribe(data =>{
this.result = data;
this.name = data[0].name; //access the index you need
});
并将其用作,
<input type="text" [(ngModel)]="name ">
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句