2017-04-04 27 views
0

我是AngularJS的新手。使用$ http服务,我要求从本地主机的HTML页面。但我得到的是该页面的源代码而不是结果。

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> 

文件/ myFile.html

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

我怎么能显示myFile.html,而不是源代码中的标题。

+0

@MohammedSiyab:你的意思是使从服务器端的HTML文件,或者你只是想将它绑定到HTML? –

+0

如果从客户端查找填充文件或者可以插入查看也使用ng-src –

+1

什么是源代码而不是HTML页面,是不是HTML代码的源代码? – maurycy

回答

0

可以尝试通过注入$ SCE分配的价值和使用的代码更改如下,

$http.get('files/myFile.html').then(function(response){ 
    $scope.reqData = $sce.trustAsHtml(response.config); 
}); 
相关问题