zoukankan      html  css  js  c++  java
  • AngularJS(5)-Http

    $http 是 AngularJS 中的一个核心服务,用于读取远程服务器的数据

    加入下面有一个存储在web服务器上的数据,假设地址为http://TestWebData/myData.php

    {
    "records":
    [
    {
    "Name" : "Alfreds Futterkiste",
    "City" : "Berlin",
    "Country" : "Germany"
    },
    {
    "Name" : "Berglunds snabbköp",
    "City" : "Luleå",
    "Country" : "Sweden"
    },
    {
    "Name" : "Centro comercial Moctezuma",
    "City" : "México D.F.",
    "Country" : "Mexico"
    },
    {
    "Name" : "Ernst Handel",
    "City" : "Graz",
    "Country" : "Austria"
    },
    {
    "Name" : "FISSA Fabrica Inter. Salchichas S.A.",
    "City" : "Madrid",
    "Country" : "Spain"
    },
    {
    "Name" : "Galería del gastrónomo",
    "City" : "Barcelona",
    "Country" : "Spain"
    },
    {
    "Name" : "Island Trading",
    "City" : "Cowes",
    "Country" : "UK"
    },
    {
    "Name" : "Königlich Essen",
    "City" : "Brandenburg",
    "Country" : "Germany"
    },
    {
    "Name" : "Laughing Bacchus Wine Cellars",
    "City" : "Vancouver",
    "Country" : "Canada"
    },
    {
    "Name" : "Magazzini Alimentari Riuniti",
    "City" : "Bergamo",
    "Country" : "Italy"
    },
    {
    "Name" : "North/South",
    "City" : "London",
    "Country" : "UK"
    },
    {
    "Name" : "Paris spécialités",
    "City" : "Paris",
    "Country" : "France"
    },
    {
    "Name" : "Rattlesnake Canyon Grocery",
    "City" : "Albuquerque",
    "Country" : "USA"
    },
    {
    "Name" : "Simons bistro",
    "City" : "København",
    "Country" : "Denmark"
    },
    {
    "Name" : "The Big Cheese",
    "City" : "Portland",
    "Country" : "USA"
    },
    {
    "Name" : "Vaffeljernet",
    "City" : "Århus",
    "Country" : "Denmark"
    },
    {
    "Name" : "Wolski Zajazd",
    "City" : "Warszawa",
    "Country" : "Poland"
    }
    ]
    }
    

      

    AngularJS 实例
    <div ng-app="myApp" ng-controller="customersCtrl"> 
    
    <ul>
      <li ng-repeat="x in names">
        {{ x.Name + ', ' + x.Country }}
      </li>
    </ul>
    
    </div>
    
    <script>
    var app = angular.module('myApp', []);
    app.controller('customersCtrl', function($scope, $http) {
        $http.get("http://www.runoob.com/try/angularjs/data/Customers_JSON.php")
        .success(function(response) {$scope.names = response.records;});
    });
    </script>
    

      

  • 相关阅读:
    sshpass做秘钥分发,ansible做自动化运维工具
    Day7 面向对象和类的介绍
    R-aggregate()
    R-seq()
    R-ts()
    R-ets()
    python-无联网情况下安装skt-learn
    python-线性回归预测
    python-matplotlib-ERROR
    python-pyhs2
  • 原文地址:https://www.cnblogs.com/yk123/p/5911809.html
Copyright © 2011-2022 走看看