如何使用 angular 从网络端点获取数据?
how to use angular to get data from a web endpoint?
我需要使用 angular 从 Web 端点获取数据,然后需要将其显示给用户。应使用 bower 配置环境,使用 grunt 作为任务管理器。
我已经安装了 bower、angular 和 boostrap,页面布局已经完成。问题是,如何从该端点获取数据以显示它? (它基本上是一个包含 ID 和名称的列表)
谢谢
尝试使用 angular 的 $http 服务从端点检索数据。
https://docs.angularjs.org/api/ng/service/$http#get
之后,在回调函数中,您将能够使用端点中的数据并将其保存到控制器中。
照常渲染。
例如:
$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.
});
我需要使用 angular 从 Web 端点获取数据,然后需要将其显示给用户。应使用 bower 配置环境,使用 grunt 作为任务管理器。
我已经安装了 bower、angular 和 boostrap,页面布局已经完成。问题是,如何从该端点获取数据以显示它? (它基本上是一个包含 ID 和名称的列表)
谢谢
尝试使用 angular 的 $http 服务从端点检索数据。 https://docs.angularjs.org/api/ng/service/$http#get
之后,在回调函数中,您将能够使用端点中的数据并将其保存到控制器中。
照常渲染。
例如:
$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.
});