AngularJS如何从ng选项中选择值
本文关键字:选择 选项 ng AngularJS | 更新日期: 2023-09-27 18:28:17
我在select ng选项中插入值,我想在下拉列表中为特定月份进行选择。这是返回所有12个月的arrray,所以我如何才能从下拉列表中只提取选定的月份。
脚本:
$scope.Month = ['Jan', 'Feb', 'March', 'April', 'May', 'June', 'July', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
$scope.selectmonth = $scope.Month;
$scope.SaveReport = function () {
PrintReportRepository.save(
{
SelectMonth: $scope.selectmonth,
},
html
<select class="form-control" ng-model="selectmonth" ng-options ="months as months for months in Month">{{months}}</select>
要设置所选的第一个项目,请使用$scope.selectmonth = $scope.Month[0]
,通过设置$scope.selectmonth = $scope.Month
U将整个阵列设置为模型
使用此代码:请参阅plunker
控制器:
$scope.Month = ['Jan', 'Feb', 'March', 'April', 'May', 'June', 'July', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
$scope.SaveReport = function () {
console.log('SelectMonth', $scope.selectmonth);
}
html:
<select class="form-control" ng-model="selectmonth" ng-options ="months as months for months in Month" ng-change="SaveReport()"></select>