如何在angularjs控制器中获取json数据

时间:2017-05-29 22:09:19

标签: angularjs json angularjs-controller

https://jsonplaceholder.typicode.com/posts我必须从此链接获取数据并在浏览器中显示。在Javascript中,我曾经使用XMLHttpRequest做它,然后使用JSON.parse(响应)解析它。有没有办法在angularjs中实现类似的东西。谢谢

1 个答案:

答案 0 :(得分:1)

您可以查看此链接angular http get

<强>样品

 $http({
     method: 'GET',
       url: '/someUrl'
   }).then(function successCallback(response) {
      // this callback will be called asynchronously
        // when the response is available
   }, function errorCallback(response) {
/ / called asynchronously if an error occurs
   // or server returns response with an error status.
});