Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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>