Code tested with angular 1.2.3