Convert angularjs service into angular 2 service when we have a service injected another service

Viewed 929

I see a code that a service (BService) injected into another service(AService):

(function() {
    "use strict"

    class AService {

        constructor(BService) {
            this.BService = BService;
        }

        static AFactory(BService) {
            return new AService(BService);
        }
    }
    AService.AFactory.$inject = ['BService'];
    angular.module('test').service('AService', AService.AFactory);
})();
  1. What is AService.AFactory.$inject doing? Why We need AFactory here? Can I remove AFactory here?

  2. I want to convert above service into following angular 2 service. Am I right?

        import { Injectable } from '@angular/core';
        import { BService } from './b.service'
    
        @Injectable()
        export class AService {
    
            constructor(private BService: BService) {
    
            }
    
    
        }
    
        angular.module('test').service('AService', AService);
    
1 Answers
Related