sti*_*bay 0 javascript angularjs
是否可以将三元运算符的输出呈现为 html?
{{ boolA ? 'Some text' : '<i class=\"fa fa-check\"></i>' }}
Run Code Online (Sandbox Code Playgroud)
还尝试修改上一个问题中的内联 if/else 指令,但也无法使其工作。
.filter('iif', ['$sce', function ($sce) {
return function (input, trueValue, falseValue) {
return $sce.trustAs('html', input ? trueValue : falseValue);
}
}])
Run Code Online (Sandbox Code Playgroud)
是的,像这样使用 ng-bind-html :
<span ng-bind-html=" your_condition ? 'html_if_true' : 'html_if_false' "></span>
根据您的要求替换值。