AngularJS code cannot detect the local file via http get

I wanted the following example file to run. The files are at https://github.com/curran/screencasts/tree/gh-pages/introToAngular/examples/snapshots/snapshot20 .
The .htm file expects a file named countries.json. I have this file (myfile.htm) and countries.json in the same directory C:\inetpub\wwwroot\ajs\ .

But apparently the html file cannot detect the countries.json file. I get empty content with the header of Country       Population when I open up the page in browser (http://localhost/ajs/myfile.htm)

I tried with the entire path like below:
   $http.get(C:\inetpub\wwwroot\ajs\countries.json').success(function(data) {

But that does not make any difference. Could you please suggest what is wrong here. Many thanks.

----myfile.htm----
<html ng-app="countryApp">
  <head>
    <meta charset="utf-8">
    <title>Angular.js Example</title>
    <script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.1/angular.min.js"></script>
    <script>
      var countryApp = angular.module('countryApp', []);
      countryApp.controller('CountryCtrl', function ($scope, $http){
        $http.get(countries.json').success(function(data) {
          $scope.countries = data;
        });
      });
    </script>
  </head>
  <body ng-controller="CountryCtrl">
    <table>
      <tr>
        <th>Country</th>
        <th>Population</th>
      </tr>
      <tr ng-repeat="country in countries">
        <td>{{country.name}}</td>
        <td>{{country.population}}</td>
      </tr>
    </table>
  </body>
</html>

Open in new window

toookiAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dave BaldwinFixer of ProblemsCommented:
I don't much about Angular but you keep leaving off the opening quote in your statements.  Should be like this:
$http.get('countries.json').success(function(data) {

Open in new window

https://docs.angularjs.org/api/ng/service/$http
0
leakim971PluritechnicianCommented:
yes, the code work fine, just a typo error

<html ng-app="countryApp">
  <head>
    <meta charset="utf-8">
    <title>Angular.js Example</title>
    <script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.1/angular.min.js"></script>
    <script>
      var countryApp = angular.module('countryApp', []);
      countryApp.controller('CountryCtrl', function ($scope, $http){
        $http.get('countries.json').success(function(data) {
          $scope.countries = data;
        });
      });
    </script>
  </head>
  <body ng-controller="CountryCtrl">
    <table>
      <tr>
        <th>Country</th>
        <th>Population</th>
      </tr>
      <tr ng-repeat="country in countries">
        <td>{{country.name}}</td>
        <td>{{country.population}}</td>
      </tr>
    </table>
  </body>
</html>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
toookiAuthor Commented:
Thank you.

I tried with
     $http.get('countries.json').success(function(data) {

But still it did not work. It does not retrieve any values from the json file. I downloaded the json file from https://github.com/curran/screencasts/blob/gh-pages/introToAngular/examples/snapshots/snapshot20/countries.json
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

leakim971PluritechnicianCommented:
me too.
please confirm you're using http or https to open the page else it will not work
0
toookiAuthor Commented:
I am using http
This is the url
http://localhost/ajs/myfile.htm
or
localhost/ajs/myfile.htm
0
leakim971PluritechnicianCommented:
could you publish it over internet?
0
toookiAuthor Commented:
I tried but sorry could not succeed to publish to internet.
0
leakim971PluritechnicianCommented:
what is the issue ?
0
toookiAuthor Commented:
I can publish to my PC (localhost) as I have IIS running. How could I publish to internet?
0
leakim971PluritechnicianCommented:
you need to open port 80 (or any other) on your router and do a NAT to your localhost
0
toookiAuthor Commented:
I did not understand what you meant by open port 80. My apology.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.