1
我需要顯示JSON數據在表中,我用http.get函數來檢索JSON數據,但我無法顯示它們。angularjs不顯示JSON數據與http.get
我已經嘗試過這一點,但不工作:
HTML:
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js" />
<script>
myApp = angular.module('myApp', [])
myApp.controller('myController', function($scope, $http){
$http.get('data.json').success(function(response){
$scope.myData = response;
});
$scope.removeName = function(row) {
$scope.myData.splice($scope.myData.indexOf(row),1)
}
});
</script>
</head>
<body ng-app="myApp" ng-controller="myController">
Search: <input type="text" value="" ng-model="search" /><br><br>
<table border=1>
<tr ng-repeat = "Data in myData | filter : search">
<td>{{myData.name}}</td>
<td>{{myData.company}}</td>
<td><a href="" ng-click="removeName(data)">Remove</a></td>
</tr>
</table>
</body>
</html>
JSON:
[
{"name":"Steve Jobs", "company":"Apple"},
{"name":"Larry Page", "company":"Google"},
{"name":"Bill Gates", "company":"Microsoft"},
{"name":"Larry Ellison", "company":"Oracle"},
{"name":"Sergey Brin", "company":"Google"},
{"name":"Steve Wozniak", "company":"Apple"}
]
控制檯錯誤:
Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.5.8/$injector/modulerr?p0=myApp&p1=Error%3A%2…ogleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.5.8%2Fangular.min.js%3A21%3A179)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js:6:412
at https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js:40:222
at q (https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js:7:355)
at g (https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js:39:319)
at cb (https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js:43:336)
at c (https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js:20:390)
at Bc (https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js:21:179)
at fe (https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js:20:1)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js:317:386
at HTMLDocument.b (https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js:189:487)
有人可以幫我解決這個錯誤嗎? 感謝的
謝謝,但也與此修改結果沒有改變,在輸出我只有一行打印「Data.name」,「Data.company」和「刪除」 – Edoardo
你可以請粘貼數據集你的ajax電話正在返回?您的控制檯中是否還有錯誤? – Pirozek
是的我在控制檯文件angular.js中有一個錯誤,它是這樣的:未捕獲的錯誤:[$ injector:modulerr] http://errors.angularjs.org/1.2.26/$injector/modulerr?p0= myApp&p1 =錯誤%3A ... gleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.2.26%2Fangular.min.js%3A17%3A415)(...) – Edoardo