Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Seth Warner
Seth Warner
1,878 Points

Trying to increment the timestamp from momentJS with AngularJS, through ng-click..

<button ng-click="moment().format("MMM Do YY") = moment().format("MMM Do YY") + 1" ng-init="count=currenttimestamp">Next Date</button>
<button ng-click="moment().format("MMM Do YY") = moment().format("MMM Do YY") - 1" ng-init="count=currenttimestamp">Previous Date</button>

So I know this isn't the actual code, but how would I write this out, and why. My goal is to increment and or decrement the timestamp, at the end of the URL

1 Answer

Nate Conley
Nate Conley
16,191 Points

I think that I would definitely reference a function with ngClick. You could do something like this:

myTime = moment('your time here');

var addTime = function() {
    myTime = myTime.add('1', 'days');
}

The reference on manipulation is here: momentjs.com

Nate Conley
Nate Conley
16,191 Points

So your button would look more like this <button ng-click="addtime()"> </button>