AngularJs Note: $injector Vs $inject Vs Injector()

Following are the key differences:

 

#injector: Used to invoke or get dependencies into variables

   $injector.get('A')
   //gets the implementation of service called 'A' 

   $injector.invoke('A')
   //returns the value of implementation of service 'A'

#$inject: Used to inject dependencies into a function arguments

   var test = function('A', 'B'){} 
   test.$inject = ['A', 'B']
   $injector.invoke(explicit)

#injector(): Used on document object which is mainly used to bring non-angular environment code into angular environment.

   var $div = $('<div ng-controller="MyCtrl">{{content.label}}</div>'); 
   $(document.body).append($div); 
   angular.element(document).injector().invoke(function($compile) { 
     var scope = angular.element($div).scope(); 
     $compile($div)(scope); 
   });
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s