[英]Angular JS $http.get() doesn't work with my server, it works with localhost tho
[英]$http.get requests in Angular doesn't work
原諒我,但我是Angular的新手。 我在AngularJS中遇到$ http請求的問題。 我究竟做錯了什么? 幾乎與教程中一樣,但仍無法獲取數據。
var app = angular.module('TestApp', []);
app.controller('TestController', [$http, TestController]);
function TestController($http) {
var store = this;
store.personalInfo = [];
$http.get('/data.json')
.success(function(data){
store.personalInfo = data;
})
.error(function(){
store.personalInfo = "Error occured";
});
}
這是我的看法:
<body ng-app="TestApp" ng-controller="TestController as test">
<h1>Hello Plunker!</h1>
<p ng-repeat="item in test.personalInfo">
{{ item.firstName }}
</p>
<script data-require="angular.js@1.2.25" data-semver="1.2.25" src="https://code.angularjs.org/1.2.25/angular.js"></script>
<script src="script.js"></script>
</body>
您必須使用帶有引號的注入,更改此:
app.controller('TestController', [$http, TestController]);
這樣:
app.controller('TestController', ['$http', TestController]);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.