[英]Misunderstanding with ng-options
Well I'm seriously confused by ng-options. 好吧,我对ng-option感到非常困惑。 Why make it so difficult??
为什么要这么难?
Anyway, maybe you good folks can help lift the fog... 无论如何,也许你们好人可以帮助消除雾气...
I have an array of currencies: 我有多种货币:
["gbp", "usd", "eur"];
etc stored in: 等存储在:
$scope.providedCurrencies
I am trying to access them and display them 'The Angular Way' with ng-options in a Select menu, like so: 我正在尝试访问它们,并在“选择”菜单中使用ng-options将它们显示为“ The Angular Way”,如下所示:
<select ng-model="selectedCurrency"
ng-options="currency for currency in providedCurrencies"
ng-init="selectedCurrency=gbp">
</select>
This will then update a series of payment options to display the different monetary values, based on the currency selected. 然后,这将更新一系列付款选项,以根据所选的货币显示不同的货币值。
The problems: 问题:
The format for writing the ng-options doesn't make a lot of sense to me, even after the Angular docs and various tutorials :( 即使在Angular文档和各种教程之后,编写ng-options的格式对我也没有多大意义:(
Also even with the ng-init (from a tutorial) the Select menu will set an empty value on page load. 即使使用ng-init(来自教程),“选择”菜单也会在页面加载时设置一个空值。 This is then removed when the user selects a different value.
然后,当用户选择其他值时,将其删除。
Additionally the value of each option in the DOM is "string:gbp"
. 另外,DOM中每个选项的值为
"string:gbp"
。
There seems to be more information around when dealing with data in objects over arrays. 处理数组对象中的数据时,似乎有更多信息。 Should I do that?
我应该那样做吗? Even though the docs show options for arrays?
即使文档显示数组选项?
Please help :) 请帮忙 :)
You were forget to do single quote only: 您忘记了只做单引号:
<select ng-model="selectedCurrency"
ng-options="currency for currency in providedCurrencies"
ng-init="selectedCurrency='gbp'">
</select>
Check this: http://codepen.io/anon/pen/RrNyvb 检查此: http : //codepen.io/anon/pen/RrNyvb
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.