$http.post()方式解析

$http.post()比get方式多的一个参数为发送给后台的值,其他解释参照上一篇关于get方式解析,格式如下:

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <script src="angular.js"></script>
    <style>
        td {
            border: 1px solid red;
        }
    </style>
</head>
<body>
<!--方式控制器必须在定义的模型之内即ng-app -->
<div ng-app="mymodule1"><!--模型定义-->
    <div ng-controller="mycontroller1">
        <table>
            <tr ng-repeat="p in data">
                <td>{{p.deviceId}}</td>
                <td>{{p.handleTime}}</td>
                <td>{{p.projectId}}</td>
                <td>{{p.id}}</td>
                <td>{{p.questionType}}</td>
            </tr>
        </table>


    </div>
</div>
<script>
    //    angularjs 交互中第一步:注入$http 第二步进行请求
    //$http.get(url,'config放在地址后面的参数可有可无)').success(function(data,status,){}).error()或者直接$get(url?x=1).success()也可省略config相当于问号后边的值为config ---地址必须在同一个域下否则引起跨域
    var mymodule = angular.module("mymodule1", []);
    mymodule.controller('mycontroller1', function ($scope, $http) {
        var config = {params: {id: "female"}};//在地址传入后台的值,可有可无,必须是{params:{xx:xxxx}}的形式 params(参数)
        $get.get('exp.txt',config).success(function(data){
//        $http.get('exp.txt?id=3').success(function (data,status,headers,config) {中的问好后边的id=3相当于config的值
                $scope.data = data.data.list;
            console.log(data);
//            console.log(status)
//            console.log(headers)
//            console.log(config)
            })
        })


</script>

</body>
</html>
原文地址:https://www.cnblogs.com/bellagao/p/6278975.html