是否可以将三元运算符的输出呈现为 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/