如何设置一个变量的模板里面? [英] How to set a variable inside of a template?
本文介绍了如何设置一个变量的模板里面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我怎样才能避免在 {{F = ...}}
第三行语句打印出的预测内容[天.ISO]
?
我要避免使用预测[day.iso] .temperature
等为每次迭代。
< DIV NG重复=天forecast_days>
{{$指数}} - {{day.iso}} - {{day.name}}
{{F =预测[day.iso]}}
温度:{{f.temperature}}< BR>
湿度:{{f.humidity}}< BR>
...
< / DIV>
解决方案
使用 ngInit :<一href=\"http://docs.angularjs.org/api/ng.directive:ngInit\">http://docs.angularjs.org/api/ng.directive:ngInit
&LT; DIV NG重复=天forecast_daysNG-的init =F =预测[day.iso]&GT;
{{$指数}} - {{day.iso}} - {{day.name}}
温度:{{f.temperature}}&LT; BR&GT;
湿度:{{f.humidity}}&LT; BR&GT;
...
&LT; / DIV&GT;
例如: http://jsfiddle.net/coma/UV4qF/
How can I avoid having the {{f = ...}}
statement in the third line print out the content of forecast[day.iso]
?
I want to avoid using forecast[day.iso].temperature
and so on for every iteration.
<div ng-repeat="day in forecast_days">
{{$index}} - {{day.iso}} - {{day.name}}
{{f = forecast[day.iso]}}
Temperature: {{f.temperature}}<br>
Humidity: {{f.humidity}}<br>
...
</div>
解决方案
Use ngInit: http://docs.angularjs.org/api/ng.directive:ngInit
<div ng-repeat="day in forecast_days" ng-init="f = forecast[day.iso]">
{{$index}} - {{day.iso}} - {{day.name}}
Temperature: {{f.temperature}}<br>
Humidity: {{f.humidity}}<br>
...
</div>
Example: http://jsfiddle.net/coma/UV4qF/
这篇关于如何设置一个变量的模板里面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文