When I started using AngularJS one of the obstacles I ran into was using CoffeeScript classes to develop the controllers. Most examples show an inline JavaScript function, which I can easily duplicate with CoffeeScript. However, to make use of a CoffeeScript class, I had to play around with it till I figured it out.
In this post I’ll provide a look at converting the simple Todo app on the Angular page to CoffeeScript. I’ll cover the process I went through while figuring this out, which includes:
* A 1:1 JavaScript to CoffeeScript conversion using functions
* Using a CoffeeScript class with all functions defined in the constructor, off of $scope (don’t do this)
* Defining methods on the class instead of on $scope and assigning the class to the $scope (good)
* Using the new Angular 1.1.5+ controller as syntax and an example of CoffeeScript using a class and base class (good)
Your new post is loading...