/
numselect.js
48 lines (43 loc) · 1.21 KB
/
numselect.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
46
47
48
/*
Usage :
<num-select nb-options="5" ng-model="point"></num-select>
Valeur sélectionnée : {{point}}
<input type="button" ng-click="point = 3" value="Set to 3">
demo : http://jsfiddle.net/royto/8L1jLrf1/
*/
class NumSelect {
constructor() {
this.templateUrl = 'views/directives/num-select.html';
this.restrict = 'E';
this.scope = {
nbOptions: '=',
ngModel: '=',
onChange: '&'
};
this.require = 'ngModel';
this.link = function(scope, element, attrs, ngModelCtrl) {
scope.num = [];
var updateOptions = function () {
var i = 0;
if (angular.isDefined(attrs.startAtOne) &&
attrs.startAtOne === 'true') {
i = 1;
}
scope.num = [];
for (; i <= scope.nbOptions; i += 1) {
scope.num.push(i);
}
};
//watch to nbOptions Change
scope.$watch('nbOptions', function () {
updateOptions();
}, true);
element.bind('change', function () {
scope.$apply(function () {
scope.onChange();
});
});
};
}
}
angular.module('volleyApp').directive('numSelect', [() => new NumSelect()]);