Conditional injection of a service in AngularJS

前端 未结 3 1918
独厮守ぢ
独厮守ぢ 2020-12-11 19:53

I have defined a service like this :

angular.module(\'myApp\').service(\'myService\', [
\'$rootScope\',
...
...

I want my service to be in

3条回答
  •  难免孤独
    2020-12-11 20:50

    use factory instead of service, so that you can have some checking logic in your service

    angular.module('myApp').factory('myService', function () {
    
        if (newUser) {
            return { // your service implementation here
            }
        }
        return undefined;
    };
    

提交回复
热议问题