我需要使用angular从Web端点获取数据,然后需要将其显示给用户。应该使用bower配置环境,使用grunt作为任务管理器。
我已经安装了bower,angular和boostrap,页面的布局已经完成。问题是,如何从该端点获取数据以显示它? (它基本上是一个带有id' s和名字的列表)
谢谢
答案 0 :(得分:2)
尝试使用angular' $ http服务从端点检索数据。 https://docs.angularjs.org/api/ng/service/ $ HTTP GET#
在回调函数之后,您将能够使用端点中的数据并将数据保存到控制器中。
然后像往常一样渲染它。
E.G:
$http({method: 'GET', url: 'your url as a string'}).
then(function(response) {
// here your response goes. Use it.
// in your case - your data will be in response.data
console.log(response.data);
}, function(response) {
// here is the error if requset failed.
});