在离子框架中调用api的良好起点

时间:2016-01-12 07:06:40

标签: swift frameworks ionic

我是离子框架的新手,所以我不太了解。我想知道如何在我的应用程序中使用离子调用api?请任何人有任何想法然后建议我。

2 个答案:

答案 0 :(得分:1)

在Ionic中将API服务与AngularJS集成

 angular.module('ionicApp', [])

 .controller('MainCtrl', function($scope, $http) {
      $http.get('https://cors-test.appspot.com/test').then(function(resp) {
         console.log('Success', resp);
          // For JSON responses, resp.data contains the result
       }, function(err) {
         console.error('ERR', err);
         // err.status will contain the status code
       })
})

<强> More...

答案 1 :(得分:1)

angular.module('ionicApp', [])

.controller('MainCtrl', function($scope, $http) {
$http({
       method: method,//GET/POST/DELETE
       url: url,
       data: data,//JSON DATA FOR POST
       dataType: 'json',
       headers: {
                "Content-Type": "application/json"
       }
       }).success(function (data) {//Success handling
            console.log(data);
       }).error(function (data, status) {//Error handling
            console.log(status + data);
       });
)}

上述方法适用于任何类型的HTTP(Get / Post / Delete / Put)请求。

此致

相关问题