zoukankan      html  css  js  c++  java
  • Angular $http解析通过接口获得的json数据

      刚接触angular不久,对很多东西都不了解,今天需要用angular通过接口得到json数据,折腾了好久,总算是能获取到数据了,下面是部分源码,仅供参考:

     HTML部分:

    1 <body ng-app="httpApp">
    2         <ul ng-controller="httpController">
    3             <li ng-repeat="(key,value) in infos">
    4                 {{ key }} : {{ value}}
    5             </li>
    6             <span>{{num}}</span>
    7         </ul>
    8 </body>

    javascript部分:

     1 var app = angular.module('httpApp',[]);
     2     app.controller('httpController', function ($scope,$http) {
     3         var nprUrl = 'http://localhost:915/API/showPage/3dde3ff80b78487184d/123';
     4         $http({
     5             method: 'JSONP',                           //使用JSONP跨域
     6             url: nprUrl + '?callback=JSON_CALLBACK'     //必须加上‘?callback=JSON_CALLBACK’,得在后台处理callback,
                                       //使返回的json格式为 JSON_CALLBACK({}),我得到的不为JSON_CALLBACK,为angular.callback._0,
                                       //具体怎么用,这块没有特别明白,欢迎有了解的告知 7 }).success(function (data, status) { 8 $scope.infos = data; 9 10 }).error(function (data, status) { 11 // Some error occurred 12 }); 13 });

      可能有错误或不恰当的地方,欢迎指正或探讨,谢谢!

    --------------------------

       Miracle

        

  • 相关阅读:
    angular 中如何使用自定义组件
    angular组件数据和事件
    angular组件数据
    angular绑定数据
    angular自定义组件
    angular项目目录结构分析
    Angular 开发工具介绍
    从Microsoft.AspNet.Identity看微软推荐的一种MVC的分层架构
    EF How to use context.Set and context.Entry, which ships with EF4.1 ?
    C# 向IQueryable添加一个Include扩展方法
  • 原文地址:https://www.cnblogs.com/ethy/p/4382157.html
Copyright © 2011-2022 走看看