Skip to content

Commit

Permalink
Merge pull request #7 from Recras/attributes-when-no-value
Browse files Browse the repository at this point in the history
Set attributes even if no value is present
  • Loading branch information
timmipetit authored Feb 19, 2018
2 parents 939aca0 + 0dc3249 commit 1893579
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
24 changes: 12 additions & 12 deletions src/angular-moment-duration.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down Expand Up @@ -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));
};

Expand Down

0 comments on commit 1893579

Please sign in to comment.