angular2组件中的下拉值

时间:2017-07-06 11:40:46

标签: angular drop-down-menu angular-ngmodel

我正在尝试用这个简单的任务来探索Angular2。 我有一个选择元素,

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

我想将此选定值打印到我的控制台上,我试图在组件中访问它。

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

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

在浏览了如何从下拉列表中获取所选值的类似链接后,我可以收集到这么多信息。但现在我收到了错误

Cannot read property 'selectedChanged' of undefined

感谢任何帮助。在此先感谢:)

0 个答案:

没有答案