TypeError:$ http.get(...)。success不是函数

时间:2018-06-02 18:07:41

标签: http

<!DOCTYPE html>
<html lang="Eng">
<head>
<title>Http Demo</title>
<script 
 src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.5
 /angular.js"> 
 </script>    
<script 
  src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.5/angular- 
   route.js"></script>  
<script src="httpCont.js"></script>
 </head>
<body ng-app="mainApp">
<div ng-controller="people">
<ul>
The name and age of the persones are:</br>
<li ng-repeat="person in persons">
{{ person.name}} : {{ person.age }}
</li>
</ul>
</div>
</body>
</html>
=====================================================
httpCont.js
var app = angular.module( 'mainApp', [] )
app.controller('people', function($scope, $http) {
            $http.get('http://localhost/myAngular/database.json')
                .then(function(response) {
                    $scope.persons = response.records;
                });
});


    ====================================================================
         database.json
{
"records":[
{
    "Name" : "Umesh",
    "Age" : "30"
},

{
    "Name" : "Mahesh",
    "Age" : "27",
}
]
}
 =====================================================================

我正在研究http服务,但在运行代码时遇到错误 1)angular.js:14642 TypeError:http.get(...)。success不是函数 2)错误:[$ http:baddata]数据必须是有效的JSON对象

请有人帮我解决此问题。我已经尝试过了 与$http.get(...).success is not a function 不是功能但没有运气。提前谢谢。

0 个答案:

没有答案