Posts

Showing posts from July, 2012

Working together: AngularJS and Coffeescript

While building my first AngularJS application, I followed the official tutorial, and also other useful examples I found on the web. The examples were all in javascript of course, which was fine in the beginning, but after a while I started to miss the elegance of Coffeescript's syntax. Changing an AngularJS app from javascript is not as straight forward as changing the syntax. The reason for this is the Coffeescript compiler's reverence for the global scope. All coffee script code is wrapped in a function to protect the global scope from pollution and conflict.Take the following javascript controller definition from the official tutorial as an example. If you simply convert this to Coffeescript you will get a PhoneListCtrl not found exception in your browser console. function PhoneListCtrl($scope) { $scope.phones = [ {"name": "Nexus S", "snippet": "Fast just got faster with Nexus S."}, {"name": "Motorola XO…

AngularJs: User friendly date display with AngularJs and MomentJs

Whether you checkout Twitter or any of the other uber popular web apps, you will find dates displayed are often in a very user friendly "from now" format. Examples of this format are "Just now", "A few minutes ago", and "2 days ago". In these three examples a date value is displayed as an approximation of the difference between the absolute date value and the current time. This "from now" format could be applied on the server, but it is generally better to apply this on the client side via javascript so that it can be continually updated to reflect the every passing time. 2 javascript examples I've come across for applying the "from now" format are John Resig's lightweight pretty date library, and the other is more built-out Moment.js. In this post I explain how to apply a sliver of the power of MomentJs in an AngularJs application.
AngularJs is a delightful Client side javascript framework. One of its features is ca…