/** * 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(); }); } }; }]) });