Brijesh shah Brijesh shah - 2 months ago 17
AngularJS Question

how to inject a service on basis of condition in angular js?

There is two services in my angular app first service is for testing Demo API and second is for Live API. I want to inject those service on condition basis, how can I inject those service on condition basis.

Thanks in Advance..

Answer

You can find $Injector doc here: https://docs.angularjs.org/api/auto/service/$injector

angular.module('myApp')
.controller('myCtrl', function($injector){
 var myService;
   if(...){
     myService = $injector.get('myService');
   }

}