I've created Angular Reactive Form with boolean values of controls. I need get value from slide-toggle control and resolve condition. It looks very simply but in my code result is always false.
createForm() {
this.threatForm = this.fb.group({
threatId: 0,
name: ['', [Validators.required]],
category: [1, [Validators.required]],
description: [''],
internalExternal: [1, [Validators.required]],
securitySafety: [3, [Validators.required]],
avoidRisk: [],
shareRisk: [],
reduceRisk: [],
acceptRisk: [],
confidenciality: [false],
integrity: [false],
availability: [false],
authenticity: [false],
})
}
ngOnInit() {
this.onGetThreatsCategory();
if (this.threatForm.value.avoidRisk === true) {
console.log("Risk value: TRUE")
}
else {
console.log("Risk value: FALSE")
}
}
When I print value in HTML I'm getting good result,
AvoidRisk: {{ this.threatForm.controls.avoidRisk.value | json }}
but in TypeScript value is FALSE each time.
if (this.threatForm.value.avoidRisk === 'true')true?