我有一个html的API响应。我希望将其转换为html而不仅仅是文本。我怎么能这样做?
示例:响应是
type K = keyof ts.LanguageService
for (const k in oldLS) {
proxy[k as K] = function() {
return oldLS[k as K].apply(oldLS, arguments);
}
}
并在html中
$scope.response = response.data
如果response.content是< p>这是响应< / p为H.,
我如何使用'这是一个响应'进行角度响应,而不是上面的?
答案 0 :(得分:0)
您可以在模块中使用ng-bind-html和注入ngSanitize,如下所示:
var app = angular.module("myApp", ['ngSanitize']);
app.controller("myCtrl", function($scope) {
$scope.response={};
$scope.response={content : "<p><h1>This is response<h1></p>"};
});
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular-sanitize.js"></script>
<body>
<div ng-app="myApp" ng-controller="myCtrl">
<p ng-bind-html="response.content"></p>
</div>
</body>
</html>