2015-07-12 123 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