angular - Angular2 select with ngValue null -


here's i'm trying do: want select list bound array of objects ngvalue, first option needs "none" option null value.

model:

this.managers = [   { id: null, name: "(none)" },   { id: 1, name: "jeffrey" },   { id: 2, name: "walter" },   { id: 3, name: "donnie" }   ];  this.employee = {   name: "maude",   managerid: null }; 

view:

<select [(ngmodel)]="employee.managerid">     <option *ngfor="#manager of managers" [ngvalue]="manager.id">{{ manager.name }}</option>   </select> 

on load, list correctly binds "none" element. if change different item , back, model value switches string of 0: null. pretty inconvenient; means have intercept value , change null manually before attempt save server.

here's plunker demo: http://plnkr.co/edit/bh96rwzmvbbo63zaxgnx?p=preview

this pretty done in angular 1 <option value="">none</option>

this seems pretty common scenario, , yet i've been unable find solutions. i've tried adding <option [ngmodel]="null">none</option>, results in same 0: null value.

any suggestions?

for me looks bug, if looking fast solution, can convert null identifier string. should solve problem should additional moves make work.

see example plnkr example

or if going in way mention ng1, can this: plnkr example

i know not best solution, hope before bug fixed ng team!


Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -