Code coverage report for src/select/select.component.js

Statements: 100% (15 / 15)      Branches: 100% (6 / 6)      Functions: 100% (4 / 4)      Lines: 100% (15 / 15)      Ignored: none     

All files » src/select/ » select.component.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 461                         9   9 9             1 167   167 158   9     167     1 2   2 2 1          
angular.module('patternfly.select').component('pfSelect', {
 
  bindings: {
    selected: '=',
    options: '<',
    displayField: '@',
    emptyValue: '@',
    onSelect: '<'
  },
  templateUrl: 'select/select.html',
  controller: function () {
    'use strict';
 
    var ctrl = this;
 
    ctrl.$onInit = function () {
      angular.extend(ctrl, {
        showEmpty: angular.isDefined(ctrl.emptyValue),
        getDisplayValue: getDisplayValue,
        selectItem: selectItem
      });
    };
 
    function getDisplayValue (item) {
      var value;
 
      if (item !== ctrl.emptyValue && angular.isString(ctrl.displayField)) {
        value = item[ctrl.displayField];
      } else {
        value = item;
      }
 
      return value;
    }
 
    function selectItem (evt, item) {
      evt.preventDefault();
 
      ctrl.selected = item;
      if (angular.isFunction(ctrl.onSelect)) {
        ctrl.onSelect(item);
      }
    }
  }
});