title: Angular2 - How to initialize data inside a service?
body: <p>I have two services. <code>login.service.ts</code> and <code>environment-specific.service.ts</code>.</p>
  
  <p>In <code>login.service.ts</code> I need to initialize a Json object from <code>environment-specific.service.ts</code> which passes a couple of links.</p>
  
  <p>The use case is how to make this working in the servcie without <code>ngOnInit(){}</code>, because  <code>ngOnInit()</code> can't be used within a servcie as per Angular2 Lifecycle Hook.</p>
  
  <p>Here you find the part I must initialize inside in <code>login.service.ts</code> - of course without <code>ngOnInit()</code> method:</p>
  
  <pre><code>...
  import { EnvSpecific } from '../models/env-specific';
  import { ActivatedRoute } from "@angular/router";
  
  @Injectable()
  export class LoginService {
  
     link1: string;
     link2: string;
     link3: string;
  
     constructor(private http: Http, private fbuilder:FormBuilder, private route: ActivatedRoute) { }
  
     ngOnInit(){
        this.route.data
           .subscribe((data: { envSpecific: EnvSpecific }) =&gt; {
              this.link1 = data.envSpecific.link1;
              this.link2 = data.envSpecific.link2;
              this.link3 = data.envSpecific.link3;
        });
     }
     ...
     ...
  }
  </code></pre>
  
  <p>and I would like to pass the link(s) to the URL passed to different <code>http.post</code> API call. e.g:</p>
  
  <pre><code>...
  var obsRequest = this.http.post( this.link1, serializedForm, this.options )
  ...
  </code></pre>
  
  <p>The Error is clear: <code>link1 is undefined</code> </p>
  
  <p>Any suggestion or a hint please?</p>