2
I am trying to print the data of a JSON file in html using Angularjs, running everything through XAMPP and in my htdocs/test folder there are 3 files (index.html, main.js, test.json). The console shows no errors, I even tried debugging by firefox, I put a breakpoint in $http.get, but it never gets there. Follow the JS code:
var app = angular.module('myApp', []);
app.controller("myCtrl", function ($http, $scope) {
$http.get('teste.json').then(function (response) {
$scope.myData = response;
});
});
JSON:
[{"id":"1","name":"John"},
{"id":"2","name":"Paul"}] </br/>
HTML:
<ul>
<li ng-repeat="data in myData">
{{data.id}}
{{data.name}}
</li>
</ul>
In the network tab in Developer tools http is run?
– Sergio
Gets status 200, so I guess Sergio
– clr19
I don’t know much about angular, but as far as I know, you need to define the services that make the ajax requests and you can send them to the controller with $Scope’s
– Guilherme Lopes
@clr19 can see the answer of this 200 also?
– Sergio
Interesting is getting status 200 but is not stopping at breakpoint
– heat
I couldn’t see the answer to the 200, but I really find it strange not to stop at the breakpoint, I can’t imagine what the problem would be.
– clr19
If this is your complete HTML, it won’t work because at no point do you declare the beginning of the Angular application (with ng-app.)
– OnoSendai