Javascript AngularJS如何从ng选项中选择值
我在选择ng选项中插入值,我想在特定月份的下拉列表中选择。 这是返回所有12个月的arrray,所以如何从下拉列表中仅获取所选月份 脚本:Javascript AngularJS如何从ng选项中选择值,javascript,c#,angularjs,Javascript,C#,Angularjs,我在选择ng选项中插入值,我想在特定月份的下拉列表中选择。 这是返回所有12个月的arrray,所以如何从下拉列表中仅获取所选月份 脚本: $scope.Month = ['Jan', 'Feb', 'March', 'April', 'May', 'June', 'July', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; $scope.selectmonth = $scope.Month; $scope.SaveReport = function () {
$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>
{{months}
要设置所选的第一项,请使用$scope.selectmonth=$scope.Month[0]
,通过设置$scope.selectmonth=$scope.Month
U将整个阵列设置为一个模型使用此代码:请参阅
控制器:
$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>