错误:ng:areq Bad Argument AngularJS消耗本地API

时间:2017-01-06 11:28:46

标签: javascript angularjs

我正在开发角度,我遇到了这个错误。

  

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

     

错误:ng:areq Bad Argument;争论'人'不是一个功能,得到了   未定义。

我已经搜索了其他主题,但没有克服我的问题。

下面的代码

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 个答案:

答案 0 :(得分:0)

你需要在你的html中添加你的控制器,

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

希望这有帮助!