0

I'm new to AngularJS. Using $http service, i'm requesting an HTML page from localhost. But i'm getting the source code of that page instead of the result.

http_service.html

<!DOCTYPE html>
<html>
<head>
    <title>AngularJs | HTTP Service</title>
    <script src="js/angular.min.js"></script>
    <script>
        // Initialize the Angular Application
        var app = angular.module('myApp', []);

        // Initialize an Angular Controller
        app.controller('controller', function($scope, $http){
            // Ruquest a page from the remote server
            $http.get('files/myFile.html')
                // After initializing the $http object, run a succes function
                .then(function(response){
                    $scope.reqData = response.config;
                });
        });
    </script>
</head>
<body ng-app="myApp" ng-controller="controller">
    <h4>{{reqData}}</h4>
</body>
</html>

files/myFile.html

<!DOCTYPE html>
<html>
<head>
    <title>My file</title>
</head>
<body>
    <h1>Hello from AngularJS by Google</h1>
</body>
</html>

how can i show the heading in myFile.html instead of the source code.

MUHAMMAD Siyab
  • 436
  • 1
  • 9
  • 20

1 Answers1

0

can you try to assign the value by injecting $sce and use the code change as below,

$http.get('files/myFile.html').then(function(response){
     $scope.reqData = $sce.trustAsHtml(response.config);
});
Immanuel Kirubaharan
  • 1,094
  • 1
  • 11
  • 17