我想显示js的静态内容以及其中的图像
content = {
message: "The best city in the world?"
answer:" Paris is one of the best city.'<img src ='assets/paris.gif alt="Smiley face" height="42" width="42">'".
}
我的HTML
ng-bind-html= content.answer
当我运行代码时,提示错误
Uncaught SyntaxError: Unexpected identifier
这是我尝试过的。任何人都可以找到我的错误。谢谢。
最佳答案
您的content
字符串没有转义字符。当用双引号将字符串封装时,除非在字符串中使用转义字符\
,否则无法在字符串中再次使用它
content = {
message: "The best city in the world?",
answer: "Paris is one of the best city.'<img src =\"assets/paris.gif \" alt=\"Smiley face\" height=\"42\" width=\"42\">'"
}
如果要在角度模板中使用它,并且要渲染的答案中有
HTML
,请与ng-bind-html
一起使用