0

I am new to angularjs,

Here is my code:

<!DOCTYPE HTML>
<html ng-app="myapp">
<head>
<meta charset="utf-8">
<title>Angularjs project</title>
<script type="text/javascript" src="angular.min.js"></script>
<script>
var myapp=angular.module('myapp',[]);
myapp.controller('myctrl', function ($scope,$http) {
$http.get('countries.json').success(function(data){
$scope.countries=data;
});
});
</script>
<body>
<div ng-controller="myctrl">
<table>
<tr>
<th>country</th>
<th>population</th>
</tr>
<tr ng-repeat="country in coutries">
<td>{{country.name}}</td>
<td>{{country.population}}</td>
</tr>
</table>
</div>
</body>
</html>

And i have a json file, when it run, it doesn't work.

When i referred in google, they are saying server.js or install node.js something like that.

I just confused,what should i follow, can anyone guide me to fetching json data and display.

any help would be highly appreciated.

Thanks in advance.,

7
  • hi, for running ajax request you must run your application in a server, i suggest you to install a local web server like apache and run it from your local host and then ajax request to your json file will be work. and also you don't need nodejs for this case. Commented Feb 6, 2016 at 6:50
  • what is the ajax request? thanks Commented Feb 6, 2016 at 6:50
  • yeah.. i already run application in locahost only.. Commented Feb 6, 2016 at 6:53
  • 1
    when you are using $http in angular it's try to make an ajax request whit javascript to the desired destination and get the response back to you, check this link for more information about ajax w3schools.com/Ajax/ajax_intro.asp Commented Feb 6, 2016 at 6:54
  • 1
    if you are running it on localhost and it doesn't work, open console window inside your browser by pressing f12 key and reload the page to send resend the request, there you can see what sending and what is going back as answer to that request, check the status code or any other type of errors Commented Feb 6, 2016 at 6:55

2 Answers 2

0

Spelling mistake

$scope.countries=data;

<tr ng-repeat="country in coutries"> 

change to :

<tr ng-repeat="country in countries">
Sign up to request clarification or add additional context in comments.

1 Comment

you made it simple.. so what about that ajax request or mimetype? thanks
0

you have to include angular.js script. Can't find it in your code. Also countries.json file must be in the same level as of the above html in project structure.

2 Comments

close you <head> tag
Also there is a spelling mistake "$scope.countries=data" and "country in coutries". The spelling of countries is different. You doesn't need any extra config. It is just reading a json file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.