Search This Blog

In my daily life as a programmer I come across problems. This blog, is where I record them (and more importantly their solutions) so that I can dig them out in the future. I hope it might save others some problem solving time too.

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.

BUT, for those who like to follow best practices, and avoid the sneering of other developers the above solution might not be enough. If this is the case, you can make use of the global angular object to register a controller for a given module.

This registers the controller alright, but you might find you are still seeing the controller not found error. The reason for this is that the code using your controller expected it to be operating at the global scope as it is in the Angular tutorial.

Post a Comment

Popular posts from this blog

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…

The one thing missing from the great text editor that is Mac Vim is a project / file explorer side bar. Competing text editors such as Sublime and Text Mate have one, so why not MacVim? It doesn't seem like it would require too much additional work of the developers. Reading through debates the community has had on the issue, the reason appears to be the elitist and idealistic nature of the Mac Vim community. Please don't read that last sentence pejoratively; these guys are purists, and very good at what they do. There were quite a few in the community who believed NERDTree was more than enough for any code jocky's needs, so I decided to checkout what all the fuss was about.

I use pathogen to manage vim plugins, and it is especially useful in conjunction with a public source control system like github. Once you have pathogen installed simply pull the NerdTree Github project to your vim plugins directory.

Introduction
There are a number of different functional test frameworks that can be used with Grails. Each of which can be incorporated into the overall test infrastructure of your Grails app by including the relevant plugin:
Canoo WebtestG-FuncGebSelenium-RCWebDriver
Grails doesn't hold any opinion on which one to choose. This is fair, and gives developers choice, but it can also be a headache; one has to make the choice of which framework, and also do the necessary setup and configuration. The functional test framework of the day is currently Geb, which builds on top of another functional framework in WebDriver. Geb can be used with the test runners JUnit, TestNG, or Spock. Spock, like Geb is the tool dejour and they are commonly used together. The best thing about Spock tests is that they are easy to read.
New Dependencies in your BuildConfig
To run your functional tests you need to include a number of libraries and plugins in your BuildConfig.groovy. Here is what you typica…