2017-04-04 1 views
0

AngularJS를 처음 사용했습니다. $ http 서비스를 사용하여 로컬 호스트에서 HTML 페이지를 요청하고 있습니다. 하지만 결과 대신 해당 페이지의 소스 코드가 나타납니다.

http_service.html 내가 myfile.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> 

파일/

<!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); 
});