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
| /**
| * Created by wisestone on 2018-09-27.
| */
| 'use strict';
|
| define(['app'],
| function (app) {
| app.directive('numberOnly', ["$rootScope",
| function ($rootScope) {
| return {
| require: 'ngModel',
| restrict: 'A',
| link: function (scope, element, attrs, ngModel) {
| // DOM -> Model 갱신
| element.bind("input", function (e) {
| element.val(element.val().replace(/[e\+\-]/gi, ""));
| element.val(element.val().replace(/[^0-9]/g, ""));
|
| if ($rootScope.isDefined(attrs["maxlength"])) {
| if (element.val().length > attrs["maxlength"]) {
| element.val(element.val().slice(0, attrs["maxlength"]));
| }
| }
|
| ngModel.$setViewValue(element.val());
| scope.$digest();
| });
| }
| };
| }])
| });
|
|