Javascript html上的插值内容以字符串格式出现
角度版本1.4 所以我有这个密码 htmlJavascript html上的插值内容以字符串格式出现,javascript,angularjs,interpolation,Javascript,Angularjs,Interpolation,角度版本1.4 所以我有这个密码 html <div>{{ isConditionTrue() ? '<p>Some content<p>' : '<p>some other content</p>'}}</div> 但在用户界面上,整个插值是以字符串形式出现的 <div>"{{ isConditionTrue() ? '<p>Some content<p>' : '<p>
<div>{{ isConditionTrue() ? '<p>Some content<p>' : '<p>some other content</p>'}}</div>
但在用户界面上,整个插值是以字符串形式出现的
<div>"{{ isConditionTrue() ? '<p>Some content<p>' : '<p>some other content</p>'}}"</div>
“{{isConditionTrue()?”某些内容:“某些其他内容}”
更新:
这些值有时是字符串,有时是html。因此,如何使其通用。
有人帮忙!!!T\T您需要使用
ng bind html
查看
<div ng-bind-html="isConditionTrue()"></div>
JS
$scope.isConditionTrue = function() {
if (true) {
return '<p>IF content<p>';
} else {
return '<p>ELSE content<p>';
}
}
$scope.isConditionTrue=function(){
如果(真){
如果内容,则返回“”;
}否则{
返回“其他内容”;
}
}
如果您遇到任何问题,请告诉我。在这种情况下,您需要在ngSanitize库的帮助下使用ng bind html指令,它可以帮助您以安全的方式呈现html
var-app=angular.module(“myApp”,“ngSanitize]”);
app.controller(“myCtrl”,函数($scope){
$scope.isCondition=function(){return true;}
});代码>
您使用的是isConditionTrue
还是isCondition
?此外,要呈现HTML,还应使用
$scope.isConditionTrue = function() {
if (true) {
return '<p>IF content<p>';
} else {
return '<p>ELSE content<p>';
}
}