Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/408.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript html上的插值内容以字符串格式出现_Javascript_Angularjs_Interpolation - Fatal编程技术网

Javascript html上的插值内容以字符串格式出现

Javascript 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>

角度版本1.4

所以我有这个密码 html

 <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>';
  }
}