Domanda

I do not know why I always get this Error: Cannot call method 'post' of undefined when I press submit, please help

Html:

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

 </form>
</div>

Script:

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');
        })
    }

}]);
È stato utile?

Soluzione

The problem is with your parameter count in controller declaration

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

missing '$timeout'

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top