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

X things every JavaScript developer should know: Truthy and falsy

One thing that developers often confuses with JavaScript is Boolean logic. It seems to simple, you use for example an if statement and put a boolean expression in there and if it is true the block of code is executed other wise the else block is executed. Something like this: 1: (function () { 2: var data = []; 3:  4: if (data.length > 0) { 5: console.log("The data array is not empty"); 6: } else { 7: console.log("The data array is empty"); 8: } 9: }());   And if you run it it will do exactly what you would … Continue reading X things every JavaScript developer should know: Truthy and falsy

X things every JavaScript developer should know: use strict

In the previous blog post I explained that you should normally use an Immediately-Invoked Function Expression (IIFE) to give variables function scope. That works fine as log as we remember to declare our variables using the var keyword. However when we forget the var keyword we are back to the original problem as the variables are added to the global scope.   Leaking undeclared variables As you can see in the two code snippets below the text variables are not declared using var. Even though they are only used inside a function they are still added to the global scope. … Continue reading X things every JavaScript developer should know: use strict

X things every JavaScript developer should know: scoping

I see a lot of developer with a C# or Java background adopting JavaScript as well these days. Not that it should be a big surprise, lots of business applications are developed as client side browser based applications these days. And like it or not JavaScript is the language of the browser. Unfortunately the JavaScript syntax resembles that of Java or C# resulting in these developers thinking that they can easily master the language. And even though JavaScript is not a hard language to master there are some important differences and gotchas everyone needs to be aware of. So on … Continue reading X things every JavaScript developer should know: scoping