I have a multiple inputs form, all of them are type radio button. I need to set "required" and "checked by default" attributes, problem is Angular is not recognizing any of these. Trying to have a default checked item, I've already tried: using checked, checked=true, checked="true", [checked]="true", [checked]="{1 ==1}" ...
None has worked so far. And it's the same with "required".
Maybe is there anything I have to do on the TypeScript side? I'm using Angular 9, more specific @angular-devkit/core": "9.0.6"
Here is a little example of what I'm doing:
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-tables',
templateUrl: './perso.component.html',
styleUrls: ['./perso.component.css']
})
export class PersoComponent implements OnInit {
q1: number;
process() {
console.log(this.q1);
}
}
<form>
<div class="row">
<p>1. I am the life of the party:</p>
<label><input type="radio" name="q1" value="1" [(ngModel)]="q1" required>Very Inaccurate</label>
<br><label><input type="radio" name="q1" value="2" [(ngModel)]="q1">Inaccurate</label>
<br><label><input type="radio" name="q1" value="3" [(ngModel)]="q1" checked="true">Neither Accurate Nor Inaccurate</label>
<br><label><input type="radio" name="q1" value="4" [(ngModel)]="q1">Moderately Accurate</label>
<br><label><input type="radio" name="q1" value="5" [(ngModel)]="q1">Very Accurate</label>
{{'\nValue of q1: '+q1}}
<hr>
</div>
<button
type="submit"
class="btn btn-info btn-fill pull-right"
(click)="process()"
>Process</button>
<div class="clearfix"></div>
</form>
Thanks in advance for your help