Currently working on an Angular 2 application and facing an issue with the view code:
<select [(ngModel)]="obj.MyFlag" name="MyFlag" class="form-control col-sm-6">
<option [value]="null">N/D</option>
<option [value]="true">SI</option>
<option [value]="false">NO</option>
</select>
Here is my component code:
import { Component } from '@angular/core';
import { MyDto } from '../../../interfaces';
@Component({
selector: 'view',
template: require('./view.component.html')
})
export class MyComponentComponent {
public obj: MyDto;
constructor() {
}
public Update() {
console.log(obj.MyFlag); // Issue: "null" as string instead of null value
}
}
export class MyDto
{
public MyFlag: boolean;
}
The problem is that when selecting the first option, obj.MyFlag has a value of "null" as a string. What can be done to resolve this?
Any suggestions would be appreciated.