Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

23
  • 1
    anwere is right but whats the role of ngModel here m still confused will you exaplain it ? Commented Dec 22, 2015 at 5:48
  • 1
    @PardeepJain, using two-way data binding with NgModel causes Angular to 1) automatically update selectedDevice when the user selects a different item, and 2) if we set the value of selectedDevice, NgModel will automatically update the view. Since we also want to be notified of a change I added the (change) event binding. We shouldn't have to do it this way... we should be able to break up the two-way data binding into [ngModel]="selectedDevice" and (ngModelChange)="onChange($event)", but as I found out, onChange() gets called twice for each select list change that way. Commented Dec 22, 2015 at 16:34
  • 1
    @HongboMiao, the special $event variable/symbol is part of the "statement context" that Angular template statements have. If instead I wrote (ngModelChange)="onChange('abc')" then newValue would get the string abc. It's just normal JavaScript function calling. Commented Apr 20, 2016 at 21:21
  • 2
    @HongboMiao, use [ngValue] if you have an array of objects. Use [value] if you have an array of primitive types (string, boolean, integer). Commented May 19, 2016 at 17:21
  • 6
    $event.target.value Property 'value' does not exist on type 'EventTarget'?? can you advice for typescript 4 Commented Jun 12, 2021 at 12:22