Closed matthewjh closed 8 years ago
Wouldn't this work?
.factory('newName', function(OldName) {
return OldName;
});
We could add a sugar for this of course, but given how people are freaking out about already existing sugar (value, service etc.)...
Hmm yes, that would be equivalent to alias. It's still not smack-in-the-face obvious what it's doing at a glance though, if you're scrolling through a lot of code.
What led me to this was angular 2's bind(..).toAlias(..)
, which reads so nicely.
oldName
would still be on the injector though, so that couldn't be used for naming collisions (.rename
's use case).
Note: I'm not sure whether rename
would actually be implementable.
@matthewjh we can't simply rename, IMO, since authors of the original module would be injecting using the old names. So solving the name collision / renaming pb is a different story and would be more complex as compared to simple aliasing
Yeah, that makes sense.
I feel that the workaround for adding an alias that @pkozlowski-opensource suggested is good enough. It is very short and if it is not clear then a simple comment would suffice. As already agreed we would not be able to do a rename.
Hi,
It's a minor issue, but there's an injectable from a third-party module that I need to use but I don't like how it's named (they decided to ClassCase the name although it's not a constructor, which disagrees with my naming conventions). In this scenario, among others, e.g. a naming conflict, it'd be helpful to be able to intuitively rename or alias injectables during the config stage.
1) Is there any existing means within angular to achieve this? 2) Would
$provide.rename
and/or$provide.alias
methods be a good solution to this?$provide.rename('newName', 'oldName')