How to add year/months/day to a current date using angularJS -
i new angularjs , how add together year current date.
let's can user dob , want add together year+1.
i have tried using,
$scope.userdob = $rootscope.user.dob; $scope.userdob.add(1,'years');
but it's not working.
can help me know logic illustration ?
tia..,
it looks $rootscope.user.dob
instance of moment
moment.js
library. think main problem angular's alter detection cannot observe when mutate instance. because instance remains same internal underlying date value change. i'd suggest:
$scope.userdob = $rootscope.user.dob.clone().add(1,'years').valueof();
that way angular regular javascript date object instead of moment instance , it's alter detection work correctly.
fyi accomplish same standard javascript date instance can do:
var userdob = new date(); userdob.setyear(userdob.getfullyear() + 1)
to advance year 1.
angularjs
No comments:
Post a Comment