我有一个Angular应用程序,通过JSON文件加载数据。对于各种对象,其中一个属性是"描述"。在我的应用程序中,我通过{{item.Description}}
在我的HTML中弹出它。我的问题是JSON文件中的字符串具有需要根据变量进行调整的值。例如,"值为160(每个变量+20)"。我希望这个描述能够读出160倍于所提供变量值的20倍。
不幸的是,我不能将{{160+(20*var)}}
放在描述中,因为它只是将表达式打印为字符串。
无论如何都要以角度创建绑定,以便根据其他变量动态更新?
更新 根据要求,我尽可能多地添加代码。
在我的文件头中,我包含一个JSON文件:
<script src="path/to/file.json"></script>
然后,我有我的控制器:
app.controller('itemController', function(){
this.items = Items //Items is declared in the JSON file as the JSON object.
});
然后在我的HTML中我打电话:
<div ng-controller="itemController as ctrl">
<span class="description" ng-repeat="item in ctrl.items">
{{item.Description}}
</span>
</div>
问题是,item.Description
有我想评估的表达式。我通常会{{160+(20*ctrl.var)}}
,但由于该表达式包含在item.Description
字符串中,因此Angular不会对其进行正常评估。