I have the following HTML:
<div class="options-wrapper">
<div *ngFor="let option of options" class="option" (click)="selectOption()">
{{ option.label }}
</div>
</div>
with the following component class:
import {
Component,
ElementRef,
HostListener,
Input,
Output,
ViewChild,
} from '@angular/core';
@Component({
selector: 'mdj-select-list',
templateUrl: './select-list.component.html',
styleUrls: ['./select-list.component.scss'],
})
export class SelectListComponent {
@Input()
options: { label: string, value: string }[] = [];
selectedOption: string;
selectOption() {
console.log('click');
}
}
For some reason, I have to click the div twice in order to make the selectOption() function run. This only seems to happen when I pass in an array of objects. If I pass in an array of strings, it works as expected.
option.labelin a proper HTML element, like aul>li? Why do you want the text to be inside the div? seems like a bad HTML structure