【问题标题】:AngularJS how can select value from ng-optionsAngularJS如何从ng-options中选择值
【发布时间】:2014-10-29 05:33:34
【问题描述】:

我在选择 ng-options 中插入值,我想在下拉列表中选择特定月份。 这是返回所有 12 个月的数组,所以我怎样才能从下拉列表中只获取选定的月份。

脚本:

$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>

【问题讨论】:

    标签: javascript c# angularjs


    【解决方案1】:

    要设置第一个项目选择使用$scope.selectmonth = $scope.Month[0],通过设置$scope.selectmonth = $scope.Month U 将整个数组设置为模型

    【讨论】:

      【解决方案2】:

      使用此代码:见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>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-12-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-07-26
        • 2014-07-04
        • 2012-10-14
        相关资源
        最近更新 更多