Performance: Two-way binding with ngModel
This affects input responsiveness and rendering speed by syncing UI and data model automatically.
<input [(ngModel)]="name"><input [value]="name" (input)="name = $event.target.value">
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Manual input binding with [value] and (input) | Multiple DOM updates per event | Multiple reflows if layout changes | Higher paint cost due to frequent updates | [X] Bad |
| Two-way binding with [(ngModel)] | Single DOM update per event | Single reflow per input | Lower paint cost with optimized updates | [OK] Good |
[(ngModel)] directive do in Angular?[(ngModel)] directive binds data both ways: from component to template and back.username using ngModel?[(ngModel)].[(ngModel)]="username", which is correct. Others use only one bracket or no brackets, which is invalid for two-way binding.export class AppComponent {
name = 'Alice';
}<input [(ngModel)]="name">
<p>Hello, {{name}}!</p>[(ngModel)]="name" binds input and component property name both ways, so changing input updates name.name becomes "Bob", so {{name}} shows "Bob" in the paragraph.<input (ngModel)="email">
[(ngModel)].selectedColor using ngModel. Which code snippet correctly implements two-way binding and updates the property when the user changes the selection?[(ngModel)] syntax to sync the selected value with the component property.[(ngModel)]="selectedColor" with proper option values, enabling two-way binding.
uses one-way binding only.
uses event binding but misses the input binding part.
uses invalid syntax without brackets.Pass the test and this pattern moves unknown