0

I am trying to explore Angular2 with this simple task. I have a select element,

<select [(ngModel)]="selected" (ngModelChange)="selectedChanged()" id="boolopt">
    <option value="yes">Yes</option>
    <option value="no">No</option>
</select>

I want to print this selected value onto my console, which I am trying to access in a Component.

 @Component({
  selector: 'step',
  moduleId: module.id,
  templateUrl: 'Opt.component.html',
})

export class Opt{
  selected:string = '';
  selectedChanged() {
    console.log(this.selected);
  }
}

After going through similar links on how to get the selected value from dropdown list, I could gather so much info. But now I am getting an error

Cannot read property 'selectedChanged' of undefined

Any help is appreciated. Thanks in advance :)

Anusha
  • 647
  • 11
  • 29
  • You simply miss a quote in first line? Like : – F3L1X79 Jul 06 '17 at 11:47
  • I have tried it, and getting an error `self.context.selectedChanged is not a function` – Anusha Jul 06 '17 at 11:57
  • 2
    Your code is working perfectly. – Darshita Jul 06 '17 at 12:03

0 Answers0