Edoardo Edoardo - 16 days ago 9
AngularJS Question

angularjs doesn't show json data with http.get

i need to show json data in a table, and i used the http.get function to retreive json data but i don't be able to show them.

i've tried this but not working:

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"}

]


CONSOLE ERROR:

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)


Can someone help me to solve this error?
Thank's

Answer

Yo, you are repeating myData into Data property, but you are outputing myData :)

<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>

Try this, notice the change I made in {{ }}

Ok, this is working code - https://plnkr.co/edit/dLei9iIM9ddfBAjoAytZ I just replaced your angular with 1.5.6 and its working.

Comments