本文介绍了在Ex pression AngularJS前pression的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法让AngularJS模型数据中评估一个前pression?
Is there a way to have AngularJS evaluate an expression within model data?
HTML
<p>
{{Txt}}
</p>
结果
型号:
{
Txt: "This is some text {{Rest}}"
}
{
Rest: "and this is the rest of it."
}
最终的结果将是:这是一些文本,这是它的其余部分
推荐答案
您可以使用 $插值
服务插值字符串...
You can use the $interpolate
service to interpolate the string...
function ctrl ($scope, $interpolate) {
$scope.Txt = "This is some text {{Rest}}";
$scope.Rest = "and this is the rest of it.";
$scope.interpolate = function (value) {
return $interpolate(value)($scope);
};
}
<div ng-app ng-controller="ctrl">
<input ng-model="Txt" size="60" />
<p>{{ Txt }}</p>
<p>{{ interpolate(Txt) }}</p>
</div>
这篇关于在Ex pression AngularJS前pression的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!