Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
163
rated 0 times [  168] [ 5]  / answers: 1 / hits: 16505  / 8 Years ago, fri, june 24, 2016, 12:00:00

I just started learning Angular and I've looked on SO for a solution to load a JSON file using angular and I've done what other people have posted a solutions but I cannot get the data from my json file to show for some reason.



my json file (test.json) is simple:



{
array: [
{thing: thing1},
{thing: thing2},
{thing: thing3}
],

name: robert
}


this is my js file:



var myMod = angular.module(myMod, []);

myMod.controller(myCont, function ($scope, $http) {
$scope.thing = hi;

$http.get(/test.json)
.success(function (data) {
$scope.stuff = data.array;
$scope.name = data.name;
})
.error(function (data) {
console.log(there was an error);
});
});


and i'm trying to just display the name like this but only {{name}} shows:



<html ng-app=myMod>
<head>
<script src=angular.js></script>
<script src=testing.js></script>
</head>

<body ng-controller=myCont>
{{stuff}}
</body>
</html>

More From » html

 Answers
10

I think you had typo, you should inject $http(responsible to make an ajax call) dependency instead of $html(doesn't exist in angular)



You should change code this way.



myMod.controller(myCont, function ($scope, $html) {


to



myMod.controller(myCont, function ($scope, $http) {

[#61648] Thursday, June 23, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
alli

Total Points: 409
Total Questions: 101
Total Answers: 105

Location: The Bahamas
Member since Tue, Apr 27, 2021
3 Years ago
alli questions
Sat, Apr 23, 22, 00:00, 2 Years ago
Mon, May 18, 20, 00:00, 4 Years ago
Tue, Mar 24, 20, 00:00, 4 Years ago
Fri, Jan 24, 20, 00:00, 4 Years ago
;