gpt4 book ai didi

javascript - 具有 html 输出的 Angular 三元运算符

转载 作者:行者123 更新时间:2023-11-28 18:29:15 25 4
gpt4 key购买 nike

是否可以将三元运算符的输出呈现为 html?

{{ boolA ? 'Some text' : '<i class=\"fa fa-check\"></i>' }}

还尝试修改 previous question 中的内联 if/else 指令但也无法让它工作。

.filter('iif', ['$sce', function ($sce) {
return function (input, trueValue, falseValue) {
return $sce.trustAs('html', input ? trueValue : falseValue);
}
}])

最佳答案

是的,像这样使用 ng-bind-html :

<span ng-bind-html=" your_condition ? 'html_if_true' : 'html_if_false' "></span>

根据您的要求替换值。

关于javascript - 具有 html 输出的 Angular 三元运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38454031/

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