AngularJS $http模塊

正常還有一組數據 供測試使用測試時需要在本地環境下

<!DOCTYPE html>
 <html class="no-js" ng-app="myApp">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title></title>
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <script src="./angular.min.js"> </script>
    </head>
    <body >
        <div ng-controller="myController">
            <ul>
                <li ng-repeat="item in items" > 
                    <span>{{item.name}}</span>
                    --
                    <span>{{item.price}}</span>
                </li>
            </ul>
        </div>
    </body>
    <script>
        //angular-resource(發送網絡請求的與$http有相同功能,但是你更強大)依賴于ngResource模塊  RESTful
        var app = angular.module("myApp",[])
        app.controller("myController",["$scope","$http",function($scope,$http){
            $scope.items=[]
            //$http 是angularjs 內部自己封裝的ajax
            //$http.get()  返回一個pomise 對象
            //success和error 只是語法糖, 是對then() 封裝
            //success()和then()的對比  success()只是返回的數據對象 而then()會原樣的輸出返回值
            $http.get("./data.json").success(function(res){
                console.log(res)
            });
            $http.get("./data.json").then(function(res){
                console.log(res)
            })
        }])
    </script>
</html>```
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容

  • Spring Cloud為開發人員提供了快速構建分布式系統中一些常見模式的工具(例如配置管理,服務發現,斷路器,智...
    卡卡羅2017閱讀 134,837評論 18 139
  • 文章來自:http://blog.csdn.net/mj813/article/details/52451355 ...
    好大一只鵬閱讀 9,214評論 2 126
  • Android 自定義View的各種姿勢1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 172,841評論 25 708
  • 金融投資類公司暫停注冊與殼交易的走俏 2016年初以來,全國很多省市已經開始暫停登記注冊在名稱、經營范圍中含有金融...
    簡法幫閱讀 458評論 0 1
  • 從4:30到現在,我的神經異常興奮,因為題型的緣故。 把真題抄了一遍后,發現,每一年我大概有4個不確定。這個又是一...
    hsajhlla閱讀 257評論 0 1