Adapted for angular 1.3