From 0dc3249d878c20268c7fb92eeace722a6303ed8a Mon Sep 17 00:00:00 2001 From: Sander Date: Mon, 19 Feb 2018 10:18:42 +0100 Subject: [PATCH] Set attributes even if no value is present --- bower.json | 2 +- package.json | 2 +- src/angular-moment-duration.js | 24 ++++++++++++------------ 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/bower.json b/bower.json index 56bfe84..688aa39 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angular-moment-duration", - "version": "0.0.5", + "version": "0.0.6", "homepage": "https://github.com/Recras/angular-moment-duration", "description": "An AngularJS directive for moment.js duration", "main": "./src/angular-moment-duration.js", diff --git a/package.json b/package.json index 1ac6ea4..9c60e36 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular-moment-duration", - "version": "0.0.5", + "version": "0.0.6", "description": "An AngularJS directive for moment.js duration", "main": "src/angular-moment-duration.js", "scripts": { diff --git a/src/angular-moment-duration.js b/src/angular-moment-duration.js index 1337936..8e54f77 100644 --- a/src/angular-moment-duration.js +++ b/src/angular-moment-duration.js @@ -16,18 +16,6 @@ angular.module('ui.moment-duration', []) }, link: function(scope, element, attrs, ngModel) { ngModel.$render = function() { - if (!ngModel.$modelValue) { - return; - } - var duration = moment.duration(ngModel.$modelValue); - - var value; - if (attrs.maxUnit === undefined) { - value = duration.get(scope.type); - } else { - value = duration.as(scope.type); - } - if (attrs.type === undefined) { attrs.$set('type', 'number'); } @@ -58,6 +46,18 @@ angular.module('ui.moment-duration', []) } } + if (!ngModel.$modelValue) { + return; + } + var duration = moment.duration(ngModel.$modelValue); + + var value; + if (attrs.maxUnit === undefined) { + value = duration.get(scope.type); + } else { + value = duration.as(scope.type); + } + element.val(Math.floor(value)); };