2016-05-14 60 views
2

我使用NG綁定,HTML渲染HTML代碼到我的網頁渲染,但我的代碼太長。所以我把它放在一個HTML文件中。我怎樣才能做到這一點? 這是我的HTML和JS controller.My頁包括此:如何從一個HTML文件中使用Angularjs NG綁定,HTML

<div ng-controller="modalPopup"><div ng-bind-html="renderHtml(message)"></div></div> 

JS控制器:

angular.module('mainApp', []). 
controller('modalPopup', function($scope, $http,$sce) { 
    $scope.renderHtml = function(value) { 
    return $sce.trustAsHtml(value); 
    }; 
    $scope.message = ''; 
}); 

我想把代碼HTML的一大塊$scope.message 我怎樣才能做到這一點。感謝所有:)

回答

1

如果要包括文件內容到HTML,那麼你應該使用ngInclude:

<div ng-controller="modalPopup"><p ng-include="'path/to/file.html'"></p></div> 
+0

有在包括路徑的單引號是很重要的。謝謝。 – newman

相關問題