【发布时间】:2020-06-16 05:07:59
【问题描述】:
我有一个脚本,它从包含一些 HTML 的 API 调用中获取数据,以便在 HTML 上正确显示数据。我从 python 获取数据并使用flask http post将其保存到AngularJs中的变量中。
请看这个jsfiddle: https://jsfiddle.net/2mydubL8/
HTML:
<div ng-app ng-controller="htmController">
<input type="submit" ng-click="submit()" value="Submit"></input>
<pre>{{output}}</pre> </div>
JS:
function htmController($scope) {
//Result data comes from an API call and looks something like below
$scope.result = '\r\n<b><mark>Hostname: switch_01:</mark></b>\r\n\r\n\r\nservice password-encryption\r\nservice compress-config\r\n!\r\nhostname switch_01\r\n!\r\nlogging buffered informational\r\nno logging console\r\naaa new-model\r\naaa authentication login default group tacacs+ line\r\n\r\n<b><mark>Hostname: switch_02:</mark></b>\r\n\r\n\r\nservice password-encryption\r\nservice compress-config\r\n!\r\nhostname switch_02\r\n!\r\nlogging buffered informational\r\nno logging console\r\naaa new-model\r\naaa authentication login default group tacacs+ line\r\n';
$scope.submit = function () {
$scope.output = $scope.result;
}
};
我希望 HTML 页面应用 and 标记,而不是像在 jsfiddle 中那样将标记显示为输出。
我希望 HTML 上的输出将显示“主机名:”行,并带有粗体 () 和 突出显示()。请指教。
谢谢
【问题讨论】:
-
试试ng-bind-html。
标签: javascript html angularjs