我是angularjs的新手并尝试使用ng-repeat
但是如果我尝试在嵌套标签中打印它,某种方式ng-repeat的键/值是不可见的
工作:
<div>
<table>
<tr ng-repeat="prop in array">
<td><span ng-bind-html="prop.field1"></span></td>
</tr>
</table>
</div>
以下代码无效: -
<div ng-repeat="prop in array">
<table>
<tr>
<td><span ng-bind-html="prop.field1"></span></td>
</tr>
</table>
</div>
更新
var $app = angular.module('apps', ['ngSanitize']);
$app.controller('cntr', ['$scope', function($scope) {
$scope.guestList = [{
dob: '12/12/12'
}];
}]);
答案 0 :(得分:1)
要让html在角度js中正确显示,你必须使用AngularJS的$ sce提供程序对其进行“消毒”。请在此处阅读:https://docs.angularjs.org/api/ng/service/ $ sce
原则上,在将变量绑定到html输出之前,必须像这样清理它:
$scope.guest.sanitizedInput = $sce.trustAsHtml($scope.guest.res_addr1);
和html:
<td class="table-column-value res-addr1-value"><span ng-bind-html="guest.sanitizedInput"></span>