import { Component, OnInit, Input, Output, EventEmitter, AfterViewInit, ElementRef } from '@angular/core';

@Component({
  selector: 'neu-option',
  templateUrl: './neu-option.component.html',
  styleUrls: ['./neu-option.component.css']
})
export class NeuOptionComponent implements OnInit, AfterViewInit {

  @Input() value:any;
  @Output('selected') selected = new EventEmitter<any>();
  public html:string;
  @Input() text:string;

  constructor(private eRef:ElementRef) { }

  ngOnInit() {
  }
  
  ngAfterViewInit() {
    this.html = this.eRef.nativeElement.firstElementChild.innerHTML;
    if(!this.text) this.text = this.eRef.nativeElement.firstElementChild.textContent;
  }

  onClick() {
    this.selected.emit({
      value: this.value,
      html: this.html,
      text: this.text
    });
  }

}