gpt4 book ai didi

javascript - 具有 HTML 格式的 AngularJS 动态行生成

转载 作者:太空宇宙 更新时间:2023-11-04 02:23:13 26 4
gpt4 key购买 nike

我正在使用 ng-repeat 在 HTML 上生成表格行。我的行内容中有 HTML 标记,我想用它来格式化内容。但它只会将带有 html 标记的文本打印为纯文本,而不会将它们识别为 HTML 标记。

<tr ng-repeat=" styleRowDetail in styleRowDetails">
<td>{{styleRowDetail.shortMessage}}
</td>
<td>{{styleRowDetail.classOriginated}}
</td>
<td>{{styleRowDetail.method}}
</td>
<td>{{styleRowDetail.lineRange}}
</td>
<td>{{styleRowDetail.details}}
</td>
</tr>

This is what my HTML output looks like I want to get the HTML tags in column 3 to be applied to the text.

最佳答案

这是一个工作代码。

var jsondata = [{
"shortMessage": "data 1",
"classOriginated": "data 2",
"method": "<i>data 3</i>",
"lineRange": "data 4",
"details": "<b>data 5</b>"
}];

var app = angular.module('myApp', ['ngSanitize']);
app.controller('MyCtrl', function($scope, $sce) {
$scope.styleRowDetails = jsondata;
});
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-sanitize.js"></script>
<script src="controller.js"></script>
<h3>Data</h3>
<div ng-app="myApp" ng-controller="MyCtrl">
<table>
<tr ng-repeat=" styleRowDetail in styleRowDetails">
<td ng-bind-html="styleRowDetail.shortMessage">
</td>
<td ng-bind-html="styleRowDetail.classOriginated">
</td>
<td ng-bind-html="styleRowDetail.method">
</td>
<td ng-bind-html="styleRowDetail.lineRange">
</td>
<td ng-bind-html="styleRowDetail.details">
</td>
</tr>
</table>

</div>

希望对您有所帮助:)

关于javascript - 具有 HTML 格式的 AngularJS 动态行生成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37772779/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com