Can't get the input value that was sent to my component


#1

Hi guys,
I’m probably missing something trivial but i can’t sent an input to my component.

Here’s the component code:

import {Component, Input, Output, EventEmitter} from '@angular/core';
import {DAOLocation} from '../../dao/dao-location';

@Component({
  selector: 'location-select',
  templateUrl: 'build/components/location-select/location-select.html',
  inputs: ['unit_id', 'location_id'],
  outputs: ['changeLocation']
})
export class LocationSelect {
  constructor() {
    console.log(this.unit_id);
    this.locations = [];
    this.changeLocation = new EventEmitter();

  }
}

And here’s the way I am passing the values:

<location-select [unit_id]="preventive.equipment.unit_id"
                 [location_id]="preventive.equipment.location_id"
                 (changeLocation)="updateLocation($event)">
</location-select>

The following line returns undefined and the preventive.equipment.unit_id has the value of 10.

console.log(this.unit_id);

Am I missing something?

Any help will be appreciated.


#2

in constructor all inputs are undefined yet. You could get it in ngOnInit method


#3

Thank you very much!