title: Angular: function calling on constructor
body: <p>I'm following <a href="https://auth0.com/blog/real-world-angular-series-part-2/" rel="nofollow noreferrer">this auth0 tutorial</a>, and it says there:</p>
  
  <blockquote>
    <p>The authentication service's handleAuth() method must be called in the app.component.ts constructor so it will run on initialization of our app:</p>
  </blockquote>
  
  <pre><code>// src/app/app.component.ts
  import { AuthService } from './auth/auth.service';
  ...
    constructor(private auth: AuthService) {
      // Check for authentication and handle if hash present
      auth.handleAuth();
    }
  ...
  </code></pre>
  
  <p>However, documentations and answers like <a href="https://stackoverflow.com/questions/35763730/difference-between-constructor-and-ngoninit">this one</a> say:</p>
  
  <blockquote>
    <p>Mostly we use <code>ngOnInit</code> for all the initialization/declaration and avoid stuff to work in the constructor. The constructor should only be used to initialize class members but shouldn't do actual "work".</p>
  </blockquote>
  
  <p>In the tutorial, the author does uses ngOnInit on app.component.ts to run code that deals with the responsive part of the layout:</p>
  
  <pre><code>// src/app/app.component.ts
   ngOnInit() {
        Observable.fromEvent(window, 'resize')
          .debounceTime(200)
          .subscribe((event) =&gt; this._resizeFn(event));
  
        this._initWinHeight = window.innerHeight;
        this._resizeFn(null);
  
      }
  </code></pre>
  
  <p>Why use different initialization methods? Does the function calling inside the constructor, in this case, serves some purpose?</p>
  
  <p>And, please, correct me if I'm saying anything wrong. I'm new to this. Any input is appreciated.</p>