我有一个下拉列表,它是两个值的组合:engine.number和engine.name。选择一个选项后,应调用passNumber()函数。在选择选项后调用该函数,但它不传递“engine.number”值。当我调试js函数时,它变为'undefined'。我在这里缺少什么?
HTML:
<div class="controls">
<select class="span3" ng-model="selectedEngine" ng-options='engine.element as (engine.number + " " + engine.name) for engine in engines' data-ng-change="passNumber(engine.number)">
<option value="">Please Select...</option>
</select>
<span class="help-inline" id="loadingEngines" rel="spinner"></span>
</div>
功能:
$scope.passNumber = function(number) {
//do something
}
编辑:
我尝试使用selectedEngine,selectedEngine.number,engine,engine.number传递它们都是'undefined'
答案 0 :(得分:2)
这是因为它不知道你试图通过哪个重复实例。您需要传入flavien:mypassword
- 所以将模型更改为整个对象并传递:
ngModel
答案 1 :(得分:0)
首先...... 是选择加载数据吗?也许你没有使用控制器指令。
<div class="controls" data-ng-controller="MyController">
<select class="span3" ng-model="selectedEngine" ng-options='engine.element as (engine.number + " " + engine.name) for engine in engines' data-ng-change="passNumber(engine.number)">
<option value="">Please Select...</option>
</select>
<span class="help-inline" id="loadingEngines" rel="spinner"></span>
答案 2 :(得分:0)
更改您的ng-options data-ng-change
以传递来自ng-model的selectedEngine
:
<div class="controls">
<select class="span3" ng-model="selectedEngine" ng-options='engine.element as (engine.number + " " + engine.name) for engine in engines' data-ng-change="passNumber(selectedEngine)">
<option value="">Please Select...</option>
</select>
{{ selected }}
</div>
请参阅Plunkr