Angular 2 attribute is undefined on ngOnInit
<p>I'm new to web developing with AngularJs 2 and <em>I don't have experience with AngularJs 1 too</em>. So, I'm sorry if I'm asking something stupid. I'm stuck on a problem and I googled it but I couldn't find any solutions for it. :/</p>

<p>The problem is:</p>

<p>I'm trying to use <strong>in a function called at the end of ngOnInit</strong> an attribute of an object that I initialize <strong>on ngOnInit</strong>, but this object is still <strong>undefined</strong>, so I get the following exception:</p>

<pre><code>Error: Uncaught (in p**strong text**romise): TypeError: Cannot read property 'secretariatId' of undefined
</code></pre>

<p>Here is my component:</p>

<pre><code>import {Component, OnInit, AfterViewChecked} from '@angular/core';
import { ActivatedRoute, Router, Params } from '@angular/router';

import {StudentService} from './services/student.service';
import {Student} from './services/student';

import {SecretariatService} from './services/secretariat.service';

import {DisciplineService} from './services/discipline.service';
import {Discipline} from './services/discipline';


@Component({
  selector: 'fountain-enrollstudent',
  template: require('./templates/enrollstudent.component.html')
})
export class EnrollStudentComponent implements OnInit, AfterViewChecked {
  public text: string;
  selectedDiscipline: Discipline;
  disciplines: Discipline[];
  student: Student;

  constructor(
    private disciplineService: DisciplineService,
    private studentService: StudentService,
    private secretariatService: SecretariatService,
    private router: Router,
    private route: ActivatedRoute
  ) {
    this.text = 'My brand new component!';
  }

   ngOnInit(): void {
    this.route.params.forEach((params: Params) =&gt; {
      console.log(params);
      let id = +params['id'];
      this.getStudent(id);
      console.log(id);
      console.log(this.student);
      this.getDisciplines(this.student.secretariatId);
     });

     console.log(this.student);

   }

  // Understand the best moment to call it. Ps.: It doesn't work on ngOnInit
  getDisciplines(secretariatId: number): void {
     this.disciplineService.getDisciplinesBy(secretariatId)
      .then(disciplines =&gt; this.disciplines = disciplines);
  }

  getStudent(id: number): void {
     this.studentService.getStudent(id)
       .then(student =&gt; this.student = student);
  }

  onSelect(discipline: Discipline): void {
     this.selectedDiscipline = discipline;
  }
}
</code></pre>

<p>Here is my template:</p>

<pre><code>&lt;div class="text-center"&gt;
  &lt;h4&gt;Disciplines:&lt;/h4&gt;
  &lt;ul class="list-unstyled"&gt;
    &lt;li *ngFor="let discipline of disciplines" (click)="onSelect(discipline)" [class.selected]="discipline === selectedDiscipline"&gt;
      &lt;h4&gt;
        &lt;a&gt;{{discipline?.name}}&lt;/a&gt;
      &lt;/h4&gt;
    &lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</code></pre>

<p>Here is the DisciplineService:</p>

<pre><code> import { Injectable } from '@angular/core';

 import { Discipline } from './discipline';
 import { DISCIPLINES } from './mock-disciplines';

@Injectable()
export class DisciplineService {

  getDisciplines(): Promise&lt;Discipline[]&gt; {
    return Promise.resolve(DISCIPLINES);
  }

  getDisciplinesBy(secretariatId: number): Promise&lt;Discipline[]&gt; {
     return this.getDisciplines()
      .then(disciplines =&gt; disciplines.filter(discipline =&gt; discipline.secretariatId === secretariatId));
  }
}
</code></pre>

<p>I was looking for another Lifecycle Hooks to call the function getDisciplines(id: number), but I tried them all and I had no good results. :/</p>

<p>Thanks in advance!</p>