Speeding up your AngularJS applications

In general AngularJS applications are quite fast, specially when compared to more traditional browser based applications that constantly post back to the server. However there are always a few things that will help performance and make an application even faster.   Disabling Debug Data Normally AngularJS adds several things like CSS classes and some scope related properties to DOM elements. This is not really needed to run the application and is really only done to help development tools like Protractor and Batarang. When the application is in production that is not really needed and you can save some overhead by … Continue reading Speeding up your AngularJS applications

Testing an AngularJS directive with its template

  Testing AngularJS directives usually isn’t very hard. Most of the time it is just a matter of instantiating the directive using the $compile() function and interacting with the scope or related controller to verify if the behavior is as expected. However that leaves a bit of a gap as most of the time the interaction between the directives template and it’s scope isn’t tested. With really simple templates you can include them in the template property but using the templateUrl and loading them on demand is much more common, specially with more complex templates. Now when it comes to … Continue reading Testing an AngularJS directive with its template

angular.module("module") is an anti pattern

  There are two ways to use the angular.module() function. There is the call with one parameter, that returns an existing module and there is an option of using two parameter which creates a new module. The second way, where a new module is created, is perfectly fine and should be used. However the first option, where an existing module is loaded should be considered and anti pattern in most cases and should not be used unless there is an exceptional and very good reason.   What is wrong with angular.module(“module”)? Why should this usage be seen as an anti … Continue reading angular.module("module") is an anti pattern

Tracking dirty objects in AngularJS

Tracking if an object is changed or not in AngularJS is quite easy but is also part of the UI so not always completely obvious. If you want to see if there are changes the $scope or the model will not tell you. Instead you need to take a look at the ngForm FormController. It has a $dirty flag that will tell you if an object is dirty or not. Saving that to the model itself is really easy, just use an ngForm directive, and the form element is automatically an ngForm directive, and the FormController will be added to … Continue reading Tracking dirty objects in AngularJS

AngularJS and loading data over HTTP

When creating an AngularJS controller that depends on some data that needs to be loaded over HTTP it’s really tempting and easy to just inject the $http service into your controller and load the data from there. And that is exactly what I did with the moviesListCtrl. But easy and convenient doesn’t make it the best way to do so!   Services: a better approach to HTTP I strongly believe that a controller, regardless of AngularJS, MVC or WebAPI, should contain as little logic as possible. It  should just be the spider in the web and delegate to others when … Continue reading AngularJS and loading data over HTTP

Adding an AngularJS AJAX busy indicator to the RAW stack

With the typical AngularJS SPA application there are lots of AJAX calls going on to retrieve data from the server. This sometimes results in a view that appears empty to the user. The page is rendered without any data as that is still being loaded. This also happens on the movie page in the demo application. While technically completely understandable it can be confusing to an end user not seeing the expected data. While we can’t make the data appear any faster we can show the fact that the application is doing something in the background so the user knows … Continue reading Adding an AngularJS AJAX busy indicator to the RAW stack

WebAPI, PascalCase and camelCase

In the RAW stack the ASP.NET WebAPI plays a big part in exposing data to the client and accepting data back in. This does mean that it is also the boundary of the AngularJS, or JavaScript, and C# world. And both of these worlds have their own, not always compatible standards. In this case I am referring to the normal way of naming properties on objects. In C# this is normally done using PascalCase and in JavaScript this is normally done using camelCase.   Bridging the gap It turns out that being able to use the normal conventions on each … Continue reading WebAPI, PascalCase and camelCase

Using Bootstrap to make the movies list responsive

The current movie list looks quite nice on a desktop browser but leaves something to be desired on a tablet or phone. And as this is something I think should work just as well it is high time to fix this. One of the reasons I think every web application should work equally well on a tablet as on a desktop browser is that they are so frequently used. You might argue that a phone is a very limited device screen wise, and that would be true, but a tablet is becoming the default browser for quite a few people. … Continue reading Using Bootstrap to make the movies list responsive