AngularJS http 服务

来源:互联网 发布:大公司程序员职业规划 编辑:程序博客网 时间:2024/05/18 06:23

AngularJS http 服务

2017/11/20 13:28:10


效果

代码

    <!DOCTYPE html>    <html lang="en">    <head>        <meta charset="UTF-8">        <title>Title</title>        <script type="text/javascript" src="js/angular.min.js"></script>        <script type="text/javascript">            var app = angular.module("msApp", []);            app.controller("msCtrl", function ($scope, $http) {                $scope.data                $scope.httpgetthen = function () {                    $http.get("data.json").then(function (response) {                        $scope.data = response.data                    })                }            })        </script>    </head>    <body ng-app="msApp" ng-controller="msCtrl">    <button ng-click="httpgetthen()">$http.get then</button>    <p>{{data}}</p>    </body>    </html>

json数据

    [      {        "name": "ms1",        "age": "12",        "sex": "man"      },      {        "name": "ms2",        "age": "22",        "sex": "man"      },      {        "name": "ms3",        "age": "24",        "sex": "woman"      }    ]

说明

原创粉丝点击