Angular should throw an error for name collisions #13657
Description
We ran into a nasty bug where a factory we created was replacing an existing angular service in another library.
We named the factory 'dateFilter'
(it was a component for filtering items by date). Admittedly, this was a bit of a simplistic and naive name. Got a bunch of TypeErrors in the console and spent hours tracking down the fact that angular UI's bootstrap components rely on a service also named 'dateFilter'
.
Seems like it wouldn't be hard for angular to crash with a nice error message if an angular entity is registered with a duplicate name. For example, with the following code:
angular.module('main', ['sub'])
.controller('MyController', someFunc);
// Different file
angular.module('sub', [])
.controller('MyController', differentFunc);
Current behavior is that one controller would replace the other silently, resulting in difficult to find errors. Instead, why not have Angular print an error to the console complaining that 'MyController'
was declared twice?