0

I learning the $http service but I am not clear on this regarding the get(). below code doesn't execute demo2.htm. Please check and advise where i made the mistake.

var app = angular.module('myApp', []);
app.controller('urlCtrl', function($scope, $http) {
  $http.get('demo2.htm').then(function(response) {
      $scope.myWelcome = response.data;
  });
});
miquelarranz
  • 876
  • 11
  • 26
vkfjs
  • 101
  • 2
  • 11

2 Answers2

0

It seems that the $http service is not what you're looking for if you're trying to access a resource from the same location as your html/js files. One of the following should better suit your situation:

pulse0ne
  • 1,032
  • 9
  • 12
-1

Try this

var app = angular.module('myApp', []);
app.controller('urlCtrl', [
    '$scope',
    '$http',
    function($scope, $http) {
      $http.get('demo2.htm').then(function(response) {
          $scope.myWelcome = response.data;
      }
}]);
I'm Geeker
  • 4,601
  • 5
  • 22
  • 41
  • Thanks, the same code will run on the w3c tutorial but on my local system showing an issue. – vkfjs Jun 28 '16 at 13:02
  • Today's welcome message is:

    {{myWelcome}}

    var app = angular.module('myApp', []); app.controller('urlCtrl', [ '$scope', '$http', function($scope, $http) { $http.get('demo2.htm').then(function(response) { $scope.myWelcome = response.data; } }]);
    – vkfjs Jun 28 '16 at 13:02
  • Because you're running it locally, it can't make that request. You can use [http-server](https://github.com/indexzero/http-server) to fix this, and read here how to get started with angular https://docs.angularjs.org/tutorial – Alexandr Fedoseev Jun 28 '16 at 13:40