javascript - AngularJS: How to set a variable inside of a template? -


how can avoid having {{f = ...}} statement in third line print out content of forecast[day.iso]?

i want avoid using forecast[day.iso].temperature , on 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/


Comments

Popular posts from this blog

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -