Added fix from https://github.com/angular/angular.js/pull/3019/files