程序员

$HTTP服务

2018-07-12  本文已影响0人  全村的希望iOS

简介

        Angular提供了http服务与后台做交互,用法简单,让我们看看Angular提供的GET、POST。

HTTP请求

    var app = angular.module("myApp", []);

    app.controller("myController",["$scope","$http",function($scope,$http){

    方式一:

            $http.get("url").success(function(res){

                    console.log(res)//这种方式直接输出的是data数据

            }).error(function(error){

            })

方式二:

        $http({

                //配置项

                method: "GET",

                url: "url",

                params: {//post请求后台需要的参数

                        name: "Angular"

                }

         }).then(function(res) {

                console.log(res.data)

         },function(error){

        })

}])


                                                        不积跬步无以至千里,不积小流无以成江海 

上一篇 下一篇

猜你喜欢

热点阅读