Angular

angular/banana-in-box

Two-way binding is written [(prop)], brackets outside; ([prop]) silently binds an event named [prop] instead.

moderatestaticfe-angular

Why

([ngModel])="name" is read as an event binding to an event called [ngModel], which never fires. The input shows no value and typing does not update the component, with no compile error to point at the cause.

Fix

Swap the brackets: [(ngModel)]="name" (the "banana in a box": parentheses inside square brackets). With a model() input on your own component the same syntax binds both ways: [(value)]="query".

Examples

<!-- bad -->
<input id="name" ([ngModel])="name">
<!-- good -->
<input id="name" [(ngModel)]="name">

Sources

Facts

Id
angular/banana-in-box
Severity
moderate
Check
static checked in the source by audit
Applies to
angular
Only in projects with
angular
Taught by the skill
fe-angular Angular components
Since version
0.1.0

Rule file on GitHub

Read it in the terminal

npx github:dawidolko/frontend-skills explain angular/banana-in-box