2015-07-12 108 views
0

您好,我對某事感到有點困惑,當我發表我的表單數據沒有發送到服務器,我檢查了幾次我的控制檯,我無法理解發生了什麼,這是我的控制器:

angular.module('app').controller('InstCtrl', ['$http', '$scope', '$state', 'InstService', function($http, $scope, $state, InstService) { 

    var parameters = { 
     name: $scope.name, 
     description: $scope.description, 
     email: $scope.email, 
     phone: $scope.phone, 
     website: $scope.website, 
     isActive: $scope.isActive 
    }; 

    $scope.addInstitution = function(parameters) { 

     InstService.add(parameters); 
     console.log(parameters); 

    }; 

}]); 

這是服務:

angular.module('app').factory('InstService', function ($http) { 

    var InstService = {}; 

    InstService.add = function(parameters) { 

     return $http 
      .post('/api/v1/institutions/', parameters) 

    }; 

    return InstService; 
}); 

我用我的服務器上的前端和laravel 5 AngularJS。

的console.log回報不確定 和我$ http.post總是空的,因爲在沒有數據被髮送到服務器。

+0

它是什麼,你在你的控制檯,你不明白看? – Claies

+0

對不起編輯我的帖子,包括那,謝謝。 – user3718908

回答

1

你究竟在哪裏調用addInstitution方法?假設它來自您的HTML中的按鈕點擊。如果是的話,我認爲這不會起作用。您可以在設置這些範圍變量之前定義參數對象。

嘗試將參數定義成addInstitution:

$scope.addInstitution = function() { 
    var parameters = { 
     name: $scope.name, 
     description: $scope.description, 
     email: $scope.email, 
     phone: $scope.phone, 
     website: $scope.website, 
     isActive: $scope.isActive 
    }; 

    console.log(parameters); 

    InstService.add(parameters); 
}; 
+0

謝謝你的幫助。 :) – user3718908

+0

np,祝你好運,玩得開心。 – lostintranslation