2
<select id="from" multiple="multiple" name="list" ng-model="selectedVal">
    <optgroup label= "{{geo.Geo}}" ng-repeat="geo in Geographies"> 
        <option id="{{country.CountryKey}}" ng-repeat="country in geo.Country" ng-click="arrayPush()">{{country.CountryDescription}}</option>   
    </optgroup>
</select>

当我单击特定选项时,未调用 arrayPush()

$scope.arrayPush = function(){alert("Hello!");}
4

1 回答 1

1

我刚刚找到了我的问题的答案

<select id="from" multiple="multiple" name="list" ng-model="selectedVal" ng-change="arrayPush()">
    <optgroup label= "{{geo.Geo}}" ng-repeat="geo in Geographies"> 
        <option id="{{country.CountryKey}}" ng-repeat="country in geo.Country" >{{country.CountryDescription}}</option>   
    </optgroup>
</select>

不要在选项中使用 ng-click,而是在选择中使用 ng-model 和 ng-change。适用于 Chrome 和 IE

于 2013-11-26T07:55:14.180 回答