angular2-mdl-ext icon indicating copy to clipboard operation
angular2-mdl-ext copied to clipboard

object item with id=0 is not selectable

Open ozknemoy opened this issue 8 years ago • 2 comments

unsuccessfully i am trying to pick first value of an array of objects. but without multiple="true" this code works fine

 sphere =[{id:0,name:'wewe'},{id:1,name:'ghjghj'}]

<mdl-select [(ngModel)]="sphere" multiple="true" placeholder="Select countries">
      <mdl-option mdl-ripple *ngFor="let c of work_sphere" [value]="c.id">{{c.name}}</mdl-option>
</mdl-select>

ozknemoy avatar Jan 21 '17 19:01 ozknemoy

did some research and found out that inside method MdlSelectComponent.prototype.writeValue value==0 equal value==null or undefined i added strict comparison with 0 and just in case with '0' and problems gone

if ((value!==0 && value!=='0' && !value) || this.ngModel === value) {
            }
            else if (Array.isArray(value)) {
                this.ngModel = uniq(this.ngModel.concat(value));
            }
            else if (this.ngModel.indexOf(value) != -1) {
                this.ngModel = this.ngModel.filter(function (v) { return v !== value; }).slice();
            }
            else if (!!value || value===0 || value==='0') {
                this.ngModel = this.ngModel.concat([value]);
            }

can you add someting like this little rafactoring in repo?

ozknemoy avatar Jan 23 '17 18:01 ozknemoy

Hi, a pull request would be great!

mseemann avatar Jan 23 '17 19:01 mseemann