I have an application that works but shouldn't. And I would like starting correcting it.
I believe I have done things that clashes one against another, because my knowledge of Angular is low.
Commune
(City) objects, with their name, population, city code, etc./** Une commune du Code Officiel Géographique */
export interface Commune {
/** Code de la commune */
codeCommune: string;
/** Nom de la commune */
nomCommune: string;
/** Population totale de la commune. */
population: number;
/** Surface de la commune, en hectares. N\'est pas alimenté pour les arrondissements. */
surface?: number | null;
[...]
}
I'm displaying and offer to select a value by this combo-box:
<input type="text" list="communesCOG" [(ngModel)]="libelleCommuneSelectionnee" (change)="selectCommune($event.target.value)" placeholder="Tapez le nom de la commune">
<datalist id="communesCOG" >
<option *ngFor="let commune of communes" [value]="commune.codeCommune">{{commune.nomCommune}} ({{commune.nomDepartement}})</option>
</datalist>
It doesn't stop my application, but my IDE is already complaining about that:
selectCommune($event.target.value)
, with value
in red, that isn't recognized.
What surprises me, is that it is working: the code 55001
enters my function:
(where communesMap
is a communesMap: Map<string, Commune> = new Map<string, Commune>()
loaded with all the French cities, and indexed by their city code).
but there's no value
property for an Event.target
... What should have done, here?
But at the time I'm doing the selection, and until I leave the field, it only displays the city code:
There is an [(ngModel)]
on your input. Do not subscribe to (change)
event, but to (ngModelChange)
instead, where $event
is the new value:
<input type="text" list="communesCOG" [(ngModel)]="libelleCommuneSelectionnee" (ngModelChange)="selectCommune($event)" placeholder="Tapez le nom de la commune">