AngularJS - can you rename a service without modifying its core source? -


I have a situation where I have downloaded a written service for angular.js And works fine - but I call it something different in my code for convenience and readability. It's not really a necessity, it's just a wish.

I can change this by going into the actual source code for this service, but obviously all kinds of problems will have to lead. So I was thinking, is such a thing possible? Can you serve a 'alias' in your application, so that you can refer to it differently while passing through the controllers? For example ...

normal

  var app = angular Modules ('demo', [enzymominglong and obituut not announce ']); App.controller ('Home Controller', Function (NGSomingLongNum ObjectTitSNot Required) {ngSomethingLongAndObtuseThatIsNotNecessary.open ();});  

target

  var app = angular Module ('demo', [ngosominglong and obituitat not annus']); Var small name = ngSomethingLongAndObtuseThatIsNot required; App.controller ('home controller', function (short name) {smallName.open ();});  

I tried to do this, specifying it in any other variable but it does not work.

Update

I actually work some , but I'm not sure it will have poor results below the line.

  var app = angular.module ('demo', ['ngSomethingLongAndObtuseThatIsNotNecessary']); App.service ('ngSmaller', function (ngSomethingLongAndObtuseThatIsNotNecessary) {return ngSomethingLongAndObtuseThatIsNotNecessary;}); App.controller ('Home Controller', Function (NGSmler) {ngSmaller.open ();});  

You can inject it like this, in this way the form of wire in the array In the name of the attributes in the service name function, the ORDER is important

  app.controller ('HomeController', ['ngSomethingLongAndObtuseThatIsNotNecessary', function (shortName) {shortName.open (); }];  

--- Edit -----

or with the injector

  var Injector = angular indicator ([' Demo ',' ng ']); Var shortName = injector.get ('ngSomethingLongAndObtuseThatIsNotNecessary'); App.controller ('home controller', function (short-name) {shortName.open ();});  

Comments

Popular posts from this blog

Member with no value in F# -

java - Joda Time Interval Not returning what I expect -

c# - Showing a SelectedItem's Property -