AngularJS 表达式中的表达式 [英] AngularJS Expression in Expression
本文介绍了AngularJS 表达式中的表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法让 AngularJS 评估模型数据中的表达式?
HTML:
{{文本}}</p>
型号:
<代码> {Txt:这是一些文字{{Rest}}"}{休息:剩下的就这些了."}
最终结果将是:这是一些文本,这是其余部分
.
解决方案
您可以使用 $interpolate
服务对字符串进行插值...
function ctrl ($scope, $interpolate) {$scope.Txt = "这是一些文本 {{Rest}}";$scope.Rest = "这是它的其余部分.";$scope.interpolate = 函数(值){返回 $interpolate(value)($scope);};}
<小时>
<input ng-model="Txt" size="60"/><p>{{ Txt }}</p><p>{{ interpolate(Txt) }}</p>
Is there a way to have AngularJS evaluate an expression within model data?
HTML:
<p>
{{Txt}}
</p>
Model:
{
Txt: "This is some text {{Rest}}"
}
{
Rest: "and this is the rest of it."
}
The end result would be: This is some text 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>
这篇关于AngularJS 表达式中的表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文