gpt4 book ai didi

javascript - html 未在 ng-repeat 中呈现

转载 作者:行者123 更新时间:2023-11-28 20:00:13 25 4
gpt4 key购买 nike

我在 ng-repeat 中渲染一段 HTML 时遇到问题。 £ 不会呈现为 HTML,而是呈现为纯文本 - 请参阅 http://jsfiddle.net/b3Em6/1/

<div ng-app>
<ul ng-controller="CartController">
<li ng-repeat="charge in charges">
<span ng-bind-html-unsafe="charge.currencySymbol">{{charge.currencySymbol}}</span>
<span ng-bind="charge.price"></span>
</li>
</ul>
</div>

脚本

function CartController($scope) {

$scope.charges = [
{ price: 22, currencySymbol: 'C$'},
{ price: 44, currencySymbol: '&pound;'}
];
}

显示的结果是:

C$ 22
&pound; 44

如果我取出{{charge.currencySymbol}},则根本不会显示货币。我正在使用 AngularJS 1.2.7

最佳答案

ng-bind-html-unsafe 在 Angular 1.2.x 版本中不再存在。请参阅http://docs.angularjs.org/guide/migration#ngbindhtmlunsafe-has-been-removed-and-replaced-by-ngbindhtml

您需要包含 ngSanitize 模块并使用 ng-bind-html。使用最新版本的 Angular 查看更新的 fiddle :http://jsfiddle.net/b3Em6/3/

关于javascript - html 未在 ng-repeat 中呈现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21789806/

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