0
votes

I'm developing in angular and I came across this error.

Error: [ng:areq] http://errors.angularjs.org/1.5.6/ng/areq?p0=Person&p1=not%20a%20function%2C%20got%20undefined at angular.js:38 at sb (angular.js:1911) at Qa (angular.js:1921) at angular.js:10153 at $f (angular.js:9272) at n (angular.js:9065) at g (angular.js:8459) at g (angular.js:8462) at g (angular.js:8462) at g (angular.js:8462)

Error: ng:areq Bad Argument; Argument 'Person' is not a function, got undefined.

I already searched in other topics but did not overcome my problem.

code below

angular.module("myApp",[]).controller('Person', ['$scope', '$http', function($scope, $http){

        $scope.person = $http.get('http://localhost:3000/people.json').then(function(response){
            $scope.person = response.data
        });

        $scope.add = function(){
            $http({method: 'POST', url:'', data: $scope.formData})
            .then(function(response){
                 $scope.sucesso = "deu"
                 console.log(response);
             })
            .catch(function(err){
                 //your code in case your post fails
                 console.log(err);
             });
        };

    }]);


<html ng-app="myApp">

{...}

<div ng-controller="Person">
<table class="table table-bordered">
                        <tr>
                            <th ng-click="sort('name')"> Name </th>
                        </tr>
                        <tr  ng-repeat="people in person|toArray:false|filter:search|orderBy:'-created_at'">
                            <td >{{people.age}}</td>
                        </tr>
                    </table>
1

1 Answers

0
votes

You need to add your controller in your html like this,

<table class="table table-bordered" ng-controller="person">

Hope this helps!