Mik*_*378 3 javascript angularjs angular-directive bindonce
在阅读bindonce指令的文档时,我想知道bo-html和之间有什么区别bo-text.
bo-html: 评估"标记"并将其渲染为元素内的html
bo-text:评估"文本"并将其作为文本在元素内打印
所以,我希望这段代码能够工作:
<span bo-html="<strong>SomeText</strong>"></span>
Run Code Online (Sandbox Code Playgroud)
但我得到了这个:
Error: [$parse:syntax] Syntax Error: Token '<' not a primary expression at column 1 of the expression
Run Code Online (Sandbox Code Playgroud)
<strong>作为一个基本的标记,不是吗?
如果这不起作用(可能是语法问题..),bo-text和之间的真正区别是bo-html什么?
如果要将字符串抛出到bo-html中,则需要将其声明为字符串,因为它正在查找变量.
<span bo-html="'<strong>SomeText</strong>'"></span>
Run Code Online (Sandbox Code Playgroud)
其他方式:
$scope.myVariable = '<strong>SomeText</strong>';
<span bo-html="myVariable"></span>
Run Code Online (Sandbox Code Playgroud)
区别在于您复制上面的内容.您可以通过示例查看差异:
$scope.myVariable = '<strong>SomeText</strong>';
<span bo-html="myVariable"></span> //<strong>SomeText</strong> as HTML
<span bo-text="myVariable"></span> //<strong>SomeText</strong> as text
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2117 次 |
| 最近记录: |