기본적으로 내 서버에서 템플릿을 요청하고 있습니다. 이에 대한 간단한 예는 다음과 같습니다.AngularJS : 범위 변수에서 문자형 변수로 HTML 렌더링
$scope.template = {
'title': 'default',
'description': 'default template',
'html': '<html><head><style>body {background: red;}</style></head><body>{{data.name}}</body></html>'
}
$scope.data = {
name: 'John'
}
내 서버에서 수신하는 JSON 객체입니다. 이것을 DOM에 렌더링하고 싶습니다. 표시되는 것은 $scope.name
에 저장되는 것입니다.
내 각
app.filter("trust", ['$sce', function($sce) {
return function(htmlCode){
return $sce.trustAsHtml(htmlCode);
};
}]);
이있다 그리고 이것은 내 HTML에
<div ng-bind-html="template.html | trust"></div>
이는 HTML을 렌더링하지만, 잎 {{이름}}로 {{이름}} 때를 말해야한다.
https://plnkr.co/edit/5XwTMRTK83KntRP5LE8I?p=preview – nmanikiran
을 추가로 읽으십시오. https://docs.angularjs.org/api/ng/service/$compile – nmanikiran
@ManiKiran 감사합니다. 귀하의 솔루션 – notacodemonkey