src/components/select/select.js
function preLink(scope, element, attr, ctrls) {
    var selectCtrl = ctrls[0];

    element.addClass('_md');     // private md component indicator for styling

    $mdTheming(element);
    element.on('click', clickListener);
    element.on('keypress', keyListener);

    function keyListener(e) {
      if (e.keyCode == 13 || e.keyCode == 32) {
        clickListener(e);
      }
    }

    function clickListener(ev) {
      var option = $mdUtil.getClosest(ev.target, 'md-option');
      var optionCtrl = option && angular.element(option).data('$mdOptionController');
      if (!option || !optionCtrl) return;
      if (option.hasAttribute('disabled')) {
        ev.stopImmediatePropagation();
        return false;
      }

      var optionHashKey = selectCtrl.hashGetter(optionCtrl.value);
      var isSelected = angular.isDefined(selectCtrl.selected[optionHashKey]);

      scope.$apply(function() {
        if (selectCtrl.isMultiple) {
          if (isSelected) {
            selectCtrl.deselect(optionHashKey);
          } else {
            selectCtrl.select(optionHashKey, optionCtrl.value);
          }
        } else {
          if (!isSelected) {
            selectCtrl.deselect(Object.keys(selectCtrl.selected)[0]);
            selectCtrl.select(optionHashKey, optionCtrl.value);
          }
        }
        selectCtrl.refreshViewValue();
      });
    }
  }
function preLink(scope, element, attr, ctrls) {
    var selectCtrl = ctrls[0];

    element.addClass('_md');     // private md component indicator for styling

    $mdTheming(element);
    element.on('click', clickListener);
    element.on('keypress', keyListener);

    function keyListener(e) {
      if (e.keyCode == 13 || e.keyCode == 32) {
        clickListener(e);
      }
    }

    function clickListener(ev) {
      var option = $mdUtil.getClosest(ev.target, 'md-option');
      var optionCtrl = option && angular.element(option).data('$mdOptionController');
      if (!option || !optionCtrl) return;
      if (option.hasAttribute('disabled')) {
        ev.stopImmediatePropagation();
        return false;
      }

      var optionHashKey = selectCtrl.hashGetter(optionCtrl.value);
      var isSelected = angular.isDefined(selectCtrl.selected[optionHashKey]);

      scope.$apply(function() {
        if (selectCtrl.isMultiple) {
          if (isSelected) {
            selectCtrl.deselect(optionHashKey);
          } else {
            selectCtrl.select(optionHashKey, optionCtrl.value);
          }
        } else {
          if (!isSelected) {
            selectCtrl.deselect(Object.keys(selectCtrl.selected)[0]);
            selectCtrl.select(optionHashKey, optionCtrl.value);
          }
        }
        selectCtrl.refreshViewValue();
      });
    }
  }
function preLink ( scope , element , attr , ctrls ) { var selectCtrl = ctrls [ 0 ] ; element . addClass ( '_md' ) ; // private md component indicator for styling $mdTheming ( element ) ; element . on ( 'click' , clickListener ) ; element . on ( 'keypress' , keyListener ) ; function keyListener ( e ) { if ( e . keyCode == 13 || e . keyCode == 32 ) { clickListener ( e ) ; } } function clickListener ( ev ) { var option = $mdUtil . getClosest ( ev . target , 'md-option' ) ; var optionCtrl = option && angular . element ( option ) . data ( '$mdOptionController' ) ; if ( ! option || ! optionCtrl ) return ; if ( option . hasAttribute ( 'disabled' ) ) { ev . stopImmediatePropagation ( ) ; return false ; } var optionHashKey = selectCtrl . hashGetter ( optionCtrl . value ) ; var isSelected = angular . isDefined ( selectCtrl . selected [ optionHashKey ] ) ; scope . $apply ( function ( ) { if ( selectCtrl . isMultiple ) { if ( isSelected ) { selectCtrl . deselect ( optionHashKey ) ; } else { selectCtrl . select ( optionHashKey , optionCtrl . value ) ; } } else { if ( ! isSelected ) { selectCtrl . deselect ( Object . keys ( selectCtrl . selected ) [ 0 ] ) ; selectCtrl . select ( optionHashKey , optionCtrl . value ) ; } } selectCtrl . refreshViewValue ( ) ; } ) ; } }
We use preLink instead of postLink to ensure that the select is initialized before its child options run postLink.
We use preLink instead of postLink to ensure that the select is initialized before its child options run postLink .