forked from patternfly/angular-patternfly
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselect.component.js
More file actions
45 lines (37 loc) · 933 Bytes
/
Copy pathselect.component.js
File metadata and controls
45 lines (37 loc) · 933 Bytes
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
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);
}
}
}
});