zoukankan      html  css  js  c++  java
  • angularjs中下拉框select option默认值

    1.问题说明:

    option ng-repeat多空白项

    2.解决方案:

    html:

    <ion-view hide-nav-bar="true">
      <ion-content>
        <div class="list card">
          <div>
            <label class="item item-input item-select">
              <div class="input-label">
                <span>安排类型</span>
              </div>
              <select
                ng-change="selectAction()"
                ng-model="selectedType.value"
                ng-init="selectedType.value = ''"
              >
                <option value="">-- 请选择 --</option>
                <option
                  ng-repeat="item in workArrangeTypes"
                  value="{{item.value}}"
                >{{item.name}}</option>
              </select>
            </label>
          </div>
          <div class="item">
            <button style=" 100%;" class="button button-positive" ng-click="submitWork()">提交安排工作</button>
          </div>
         </div>
      </ion-content>
    </ion-view>

    js:

    /************************************** 区域管理 *************************************/
    .controller('RegionalManageCtrl', ['$scope',function($scope) {
      /*** 测试 ***/
      $scope.selectedType = {value: 1}; // 默认值
      $scope.workArrangeTypes = [
        {name: '社区服务', value: 1},
        {name: '教育学习', value: 2},
        {name: '思想汇报', value: 3},
        {name: '电话汇报', value: 4},
        {name: '家庭访问', value: 5}
      ]; // 工作安排类型
    
      // 每次option改变时自动调用该方法
      $scope.selectAction = function() {
        console.log($scope.selectedType.value); // 5
      }
    
      /**
       * 提交工作安排
       */
      $scope.submitWork = function() {
        console.log($scope.selectedType); // {value: 5}
      }
    }])

    3.效果图

  • 相关阅读:
    android system.img
    ab压力测试和CC预防
    ubuntu工具积累
    ViewManager
    PopupWindow
    singleton注意
    java byte[]生成
    java有符号无符号的转换
    C#垃圾回收Finalize 和Dispose的理解
    Silverlight 获取汉字拼音首字母
  • 原文地址:https://www.cnblogs.com/crazycode2/p/9143304.html
Copyright © 2011-2022 走看看