0

i am new AngularJs, how to debug code in angularjs using Visual Stduio 2013, i am calling RestAPI in angular but data does not show , please help me. please check below code and Images.

    var app = angular.module('myApp', []);
        app.controller('customersCtrl', function($scope, $http) {
            $http.get("http://localhost:9000/employees").then(function (response) {
                $scope.myData = response.data;

            });
        });

<!-- language: lang-html -->

      <div ng-app="myApp" ng-controller="customersCtrl">
            <pre>{{myData | json}}</pre>

            <p>Today's welcome message is:</p>

            <ul>
                <!--<li ng-repeat="x in myData">
                    {{ x.name + ', ' + x.Fname }}
                </li>-->
            </ul>


        </div>

enter image description here

enter image description here

Adeel Khan
  • 129
  • 2
  • 13
  • 2
    Possible duplicate of [How to access the services from RESTful API in my angularjs page?](http://stackoverflow.com/questions/16394089/how-to-access-the-services-from-restful-api-in-my-angularjs-page) – Julien Lopez Nov 03 '16 at 10:08

2 Answers2

0

The problem is cross-domain origin policy. Do run your index.html in a webserver and by not just loading it in browser relatively.

If you have python installed, go to your folder where the index.html is present and run the following command.

python -m SimpleHTTPServer 3000

Then fire up http://localhost:3000 in your browser, you should not have any issues.

Thalaivar
  • 23,282
  • 5
  • 60
  • 71
0

Another useful option is to use http-server from one of the npm packages.

https://www.npmjs.com/package/http-server

TheOpti
  • 1,641
  • 3
  • 21
  • 38