【发布时间】:2022-03-04 21:38:44
【问题描述】:
我有一个使用 Ng2 智能表的 Angular 应用程序,需要从 API 获取数据我创建了一个从 API 获取数据的方法(但我不知道它是否有效),主要问题是如何获取数据显示在 ng2 智能表中 以下是我的 HTML 代码
<div class="mainTbl">
<ng2-smart-table [settings]="settMain" [source]="dataMain"></ng2-smart-table>
</div>
我的服务.ts
@Injectable({
providedIn: 'root'
})
export class ClientsService {
url="http://localhost:21063/api/clints"
clients:Clients[];
constructor(private http:HttpClient) { }
getAllClients(){
this.http.get(this.url).toPromise().then(
res=>{
this.clients = res as Clients[];
}
)
}
}
组件 .ts :
export class ClientInfoComponent implements OnInit {
// start main stores tbl
settMain = {
noDataMessage: 'عفوا لا توجد بيانات',
actions: {
columnTitle: 'إجراءات',
position: 'right',
},
pager: {
perPage: 25,
},
add: {
addButtonContent: ' إضافة جديد ',
createButtonContent: '',
cancelButtonContent: '',
},
edit: {
editButtonContent: '',
saveButtonContent: '',
cancelButtonContent: '',
},
delete: {
deleteButtonContent: '',
},
columns: {
index: {
title: 'مسلسل',
width: '80px',
},
id: {
title: 'كود العميل',
width: '80px',
},
name: {
title: 'اسم العميل',
width: '160px'
},
phone: {
title: ' الهاتف'
},
address: {
title: ' العنوان'
},
nots: {
title: 'ملاحظات'
}
}
};
dataMain = [
{
index:1,
id:"",
name: "",
phone:"",
address: "",
nots: "",
}
];
// end main stores tbl
private myForm: FormGroup;
constructor(private formBuilder: FormBuilder,private Service:ClientsService) { }
ngOnInit() {
this.Service.getAllClients();
}
所以我需要一些帮助来获取数据以及如何在组件 .ts dataMain 数组中获取数据,在此先感谢并原谅我,因为我是初学者。
【问题讨论】:
-
您的服务不返回任何内容,您也没有设置 dataMain 什么内容
-
非常感谢您的支持,您能在我的示例中告诉我我是如何做到的吗?
标签: javascript angular typescript ng2-smart-table