Javascript angularjs中的单向HTML绑定

Javascript angularjs中的单向HTML绑定,javascript,angularjs,data-binding,Javascript,Angularjs,Data Binding,我曾经使用ngbind(或缩写{{}})将一些文本绑定到span中 <p>Preview: <span>formattedPrice(price)</span></p> 预览:格式化价格(价格) 如您所见,我在绑定时调用了一个函数formattedPrice。现在我意识到我应该能够在这个跨度中添加一些HTML。我尝试了ng bind html=“formattedPrice(price)”,但似乎没有成功 有没有一种方法可以在不创建另一个范围变

我曾经使用
ngbind
(或缩写{{}})将一些文本绑定到span中

<p>Preview: <span>formattedPrice(price)</span></p>
预览:格式化价格(价格)

如您所见,我在绑定时调用了一个函数
formattedPrice
。现在我意识到我应该能够在这个跨度中添加一些HTML。我尝试了
ng bind html=“formattedPrice(price)”
,但似乎没有成功


有没有一种方法可以在不创建另一个范围变量的情况下执行此操作?

您应该使用筛选器

像这样:

<p>Preview: <span>{{price | formatted}}</span></p>

确保您的应用程序加载模块:

在HTML上(示例):


如果没有此模块,Angular将无法正确解析要呈现的HTML


可能是个愚蠢的问题。但这对HTML也适用吗?假设格式化后的价格为20美元10美元,你需要这样做,这确实是个问题。也会尝试一下@johnny的答案。
angular.module('myFilters', []).filter('formatted', function() {
  return function(input) {
    //return your formatted price here
  }
}
angular.module('app', ['ngSanitize'])
<script src="<PATH_TO>/angular-sanitize.js"></script>