无法在angularjs中调用方法POST

时间:2014-01-21 03:29:23

标签: forms angularjs post form-submit

我不知道为什么当我按提交时我总是得到Error: Cannot call method 'post' of undefined,请帮助

HTML:

<div data-ng-controller="HeaderController">
 <form ng-submit="findFriend()"> 
                    <input type="email" ng-model="friendEmail">
                    <input type="submit" value="Find">

 </form>
</div>

脚本:

angular.module('mean.system').controller('HeaderController', ['$scope', 'Global', '$http', function ($scope, Global, $timeout, $http) {

    $scope.findFriend = function() {
        $scope.email = this.friendEmail;
        console.log($scope.email)
        $http.post('/findfriend', $scope.email).success(function(data) {
            $location.path('/findfriendresult');
        })
    }

}]);

1 个答案:

答案 0 :(得分:0)

问题在于控制器声明中的参数计数

angular.module('mean.system').controller('HeaderController', ['$scope', 'Global','$timeout', '$http', function ($scope, Global, $timeout, $http) {

缺少'$timeout'