【问题标题】:Get select option value when click on button in AngularJS单击AngularJS中的按钮时获取选择选项值
【发布时间】:2017-11-21 16:42:09
【问题描述】:

我无法获取选定的选项值。

查看

<select class="form-control" ng-model="mySel">
    <option ng-repeat="option in Array" value="@{{ option.id }}">@{{ option.name }}</option>
</select>

<button type="button" class="btn btn-primary" ng-click="getData(mySel);">Select</button>

控制器

scope.getData = function(selectedValue) {
    alert(selectedValue);
}

这将返回undefined

【问题讨论】:

标签: javascript angularjs html-select


【解决方案1】:

不需要从 html 传递 selectedValue 而是使用 ng-model

<button type="button" class="btn btn-primary" ng-click="getData();">Select</button>

   $scope.getData = function() {
    console.log($scope.mySel);
   }

Working fiddle

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-12-19
    • 1970-01-01
    • 1970-01-01
    • 2018-03-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多