【发布时间】:2019-06-25 05:18:23
【问题描述】:
我使用的数据库不使用布尔值 true 和 false。如何在Angular Material中为组件checkbox设置Y和N的值?
html:
<mat-checkbox formControlName="IS_ACTIVE" (change)="checkboxChange($event.checked)">
Active
</mat-checkbox>
ts:
public setValueOptions = {
onlySelf: true,
emitEvent: false,
emitModelToViewChange: false,
emitViewToModelChange: false
}
initializeForm() {
if (this.data.action == 'add') {
this.form = new FormGroup({
NAME: new FormControl(null, [Validators.required]),
IS_ACTIVE: new FormControl('Y')
})
}
}
checkboxChange(checkboxValue) {
this.form.controls.IS_ACTIVE.setValue(checkboxValue ? 'Y' : 'N', this.setValueOptions);
}
【问题讨论】:
-
在将数据发送到数据库之前将布尔值转换为
Y和N怎么样?
标签: javascript angular angular-material