I could not replicate the error message you got with your code but an error Injecting. When I fixed the problem, I was able to read the JSON:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
</head>
<body ng-app="appCursos">
<div ng-controller="meusCursosController as meusCursos">
<ul>
<p>{{ cursos.id }}</p>
<p>{{ cursos.content }}</p>
</ul>
</div>
<script type='text/javascript' src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.8/angular.min.js"></script> <script>
angular.module('appCursos', [])
.controller("meusCursosController", ['$http', '$scope', function($http,$scope) {
var baseUrl='http://rest-service.guides.spring.io/greeting';
$http.get(baseUrl).then(function(result) {
$scope.cursos = result.data;
});
}]);
</script>
</body>
</html>
It is necessary to put both $http when $Scope within the control.
Another alternative would be not to use $Scope and work with the this to access/create/attributes from/in the control itself:
var baseUrl = #...;
meusCursos = this;
meusCursos.cursos = [];
# ...
meusCursos = result.data;
# ...
And then access them in HTML as meusCursos.cursos.id
and meusCursos.cursos.content
.
Angularjs or Angular 5?
– NoobSaibot
And your model, it has how to show?
– Ramos
Paula, recommend you to do the Tour to learn how the community. Your question says you’re having trouble consuming JSON in Angular 5, but your code is Angularjs. You can edit your question and clarify better which version is using, you can also access the topic How to ask a good question?
– NoobSaibot
From what the error shows, there is no column
id
of the courses object, check the returned json with a console.log($Scope.courses), add this json to the question.– Max Rogério