How to access data while using Factory provider in angular4?

176 Views Asked by At

when i have a provider like this

  { provide: SaModelService, useValue: '[email protected]' }

i am able to get the value by just using like this in the component

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css'],
  providers: [
    { provide: SaModelService, useValue: '[email protected]' }
  ]
})
export class AppComponent implements AfterViewInit {

  constructor(private model: SaModelService) {

  }
  ngAfterViewInit() {
    console.log(this.model);
  }

}

where the service looks like this

import { Injectable } from '@angular/core';

    @Injectable()
    export class SaModelService {


    }

now, how can i get the value while using the factory provider, ie

{
      provide: APP_INITIALIZER,
      useFactory: () => function () { return '[email protected]' },
      multi: true
    }

now i have given this example just to simplify the scenerio but instead of just passing the string, i want to call some services inside the factory

my question is, is there any access to the variable, if not then how will i be getting the value which i would be using inside my component

0

There are 0 best solutions below