0
大家好,我想閱讀角一個JSON文件,但我不能也和我得到的流動錯誤閱讀JSON與AngularJS
Error: [ng:areq] http://errors.angularjs.org/1.4.3/ng/areq?
p0=jsonCtrl&p1=not%20a%20function%2C%20got%20undefined
(anonymous) @ angular.js:12330
(anonymous) @ angular.js:9109
$apply @ angular.js:15947
(anonymous) @ angular.js:1633
e @ angular.js:4450
d @ angular.js:1631
Ac @ angular.js:1651
Zd @ angular.js:1545
(anonymous) @ angular.js:28359
a @ angular.js:2996
c @ angular.js:3271
我的代碼的index.html是
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<title>Angular Quickstart</title>
<base href="/">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Polyfills -->
<script src="node_modules/core-js/client/shim.min.js"></script>
<script
src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.min.js">
</script>
<script src="node_modules/zone.js/dist/zone.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>
<script src="systemjs.config.js"></script>
<script>
System.import('main.js').catch(function(err) {
console.error(err);
});
</script>
<script type="text/javascript">
var myApp = angular.module('myApp', []);
myApp.controller('myController', function($scope, $http) {
$http.get('data.json').success(function(response) {
$scope.myData = response;
});
});
</script>
</head>
<body ng-controller="myController">
Search : <input type="text" value="" ng-model="search" />
<table border=1>
<tr ng-repeat="data in myData | filter : search">
<td>{{data.Name}}</td>
<td>{{data.Company}}</td>
<td><a href="" ng-click="removeName(data)">Remove</a></td>
</tr>
</table>
<div ng-controller="jsonCtrl">
<my-app>Loading AppComponent content here ...</my-app>
</body>
</html>
我看了很多,但我無法弄清楚。這個腳本是否必須在不同的文件?或者它是在index.html好?我真的是新的角度,我不知道如何處理這個問題
這段代碼是angularjs **不是** angular 2.語法非常不同,你可以在你的src的版本號中看到:'1.4.3'。 – 0mpurdy
@Amir我已經創建了與在線API的codepen,它工作正常,你得到的錯誤,因爲你沒有創建任何控制器jsonCtrl –