Wondering if anyone has insight into the use of ng-selected to set the
selected attribute on an option list. We use a mix of Google Soy
templates, Angular, Backbone, and CoffeeScript in our application. I
generate the the select option list as follows:
<select id="config-prefs-default-metric-id" name="METRIC_ID">
<option ng:repeat="dm in getDefaultMetrics()" value="{literal}
{{
dm.id}}{/literal}"
ng-selected="{literal}{{isMetricSelected(
dm.id,
dm.name)}}{/literal}">
{literal}{{
dm.name}}{/literal}
</option>
</select>
getDefaultMetrics: ->
return @metrics
isMetricSelected: (metricId, metricName) ->
if metricId == parseInt(@prefs.DEFAULT_METRIC_ID)
_.delay (() => $('#config-prefs-default-metric-id
option:contains(' + metricName + ')').attr('selected', 'selected')),
100
return true
else
return false
The hack I have right now requires a delay to be applied to jQuery
selector to set the selected attribute. Does Angular have a cleaner
way of setting the selected attribute that would not require this
jQuery selector? Seems that if the check for ng-selected is run that
setting the attribute would be part of the process but I may be
misunderstanding it's intent.
Thanks for the help