如何在angular js中从前端获取下拉列表的选定值
How to get the selected value of a drop down from front end in angular js
这是我的控制器
var controller = app.controller('ctrl', function ($scope) {
$scope.dropdown = ["Yearly", "Monthly", "Date"];
});
这是我的HTML内容:
<body ng-app="app" ng-controller="ctrl">
<div>
<table>
<tr>
<td>
<label>Select :</label>
</td>
<td>
<select data-ng-model="option">
<option ng-repeat="date in dropdown" ng-bind="date" value="{{date.value}}"></option>
</select>
</td>
</tr>
<tr ng-show="option == 'Yearly'">
<td>
<label>From:</label>
</td>
<td>
<input type="date" ng-model="fromdate" id="fromdate" date-picker />
</td>
<td>
<label>To:</label>
</td>
<td>
<input type="date" ng-model="todate" date-picker />
</td>
</tr>
</table>
</div>
我正在尝试获取用户从前端下拉列表中选择的值,我需要根据在下拉列表中选择的值隐藏或显示一些文本框。
ng-model 而不是 ng-bind 但是我建议使用 ng-options...
<select ng-options="date for date in dropdown" ng-model="option"></select>
文档here
使用ng-options
,
<select ng-model="selectedOption" ng-options="date for date in dropdown"></select>
您选择的选项将填充到 selectedOption
范围变量中。
这是下拉菜单 html
<select ng-model='option' ng-options="date for date in dropdown"></select>
并在控制器中定义选项
$scope.option = null
在 show/hide
那里使用此选项
这是我的控制器
var controller = app.controller('ctrl', function ($scope) {
$scope.dropdown = ["Yearly", "Monthly", "Date"];
});
这是我的HTML内容:
<body ng-app="app" ng-controller="ctrl">
<div>
<table>
<tr>
<td>
<label>Select :</label>
</td>
<td>
<select data-ng-model="option">
<option ng-repeat="date in dropdown" ng-bind="date" value="{{date.value}}"></option>
</select>
</td>
</tr>
<tr ng-show="option == 'Yearly'">
<td>
<label>From:</label>
</td>
<td>
<input type="date" ng-model="fromdate" id="fromdate" date-picker />
</td>
<td>
<label>To:</label>
</td>
<td>
<input type="date" ng-model="todate" date-picker />
</td>
</tr>
</table>
</div>
我正在尝试获取用户从前端下拉列表中选择的值,我需要根据在下拉列表中选择的值隐藏或显示一些文本框。
ng-model 而不是 ng-bind 但是我建议使用 ng-options...
<select ng-options="date for date in dropdown" ng-model="option"></select>
文档here
使用ng-options
,
<select ng-model="selectedOption" ng-options="date for date in dropdown"></select>
您选择的选项将填充到 selectedOption
范围变量中。
这是下拉菜单 html
<select ng-model='option' ng-options="date for date in dropdown"></select>
并在控制器中定义选项
$scope.option = null
在 show/hide
那里使用此选项