Why is this property undefined?
export class DataFormComponent implements OnInit {
distanceDropdownItems: any[];
constructor() { }
ngOnInit() {
this.distanceDropdownItems = DISTANCE_DROPDOWN_ITEMS;
console.log('FORMS dropdown items = ', this.distanceDropdownItems); < ---- defined ... [{},{},...]
}
}
Template:
<app-input-dropdown [dropdownItems]="distanceDropdownItems"></app-input-dropdown>
Child component:
@Component({
selector: 'app-input-dropdown',
templateUrl: './input-dropdown.component.html',
styleUrls: ['./input-dropdown.component.scss'],
encapsulation: ViewEncapsulation.None
})
export class InputDropdownComponent implements OnInit {
@Input() dropdownItems: any[];
selectedItem: any;
constructor(private el: ElementRef) { }
ngOnInit() {
console.log(this.dropdownItems); <------- Undefined
this.selectedItem = this.dropdownItems[0];
const dropdownButton = this.el.nativeElement.querySelector('.dropdown-button');
dropdownButton.classList.remove('dropdown-button');
dropdownButton.classList.add('dropdown-input-button');
}
}
<app-input-dropdown [dropdownItems]="this.distanceDropdownItems"></app-input-dropdown>? There is not "items" object in ur component.<app-input-dropdown [dropdownItems]="items"></app-input-dropdown>prop name should be[dropdownItems]not[items]ngOnChanges(changes : SimpleChanges)and check if you are getting the data inchanges.dropdownItems. you'll have both the previousValue and currentValue