K
K
Konstantin2020-09-28 12:22:32
Angular
Konstantin, 2020-09-28 12:22:32

Cannot read property 'required' of null for radio button?

There is this code:

<ng-container *ngIf="fieldDefinition.fieldtype == 'radio'">
            <div class="col-md-12">
                <label>{{ fieldDefinition.title }}</label>
                <ng-container *ngFor="let radio of fieldDefinition?.datasource?.value">
                    <div class="form-check form-check-radio">
                        <label class="form-check-label">
                            <input
                                class="form-check-input"
                                type="radio"
                                name="radio_{{ id }}"
                                #ref="ngModel"
                                id="{{ id }}"
                                (change)="handleRadioChange(fieldDefinition)"
                                [checked]="radio.id == fieldDefinition.fieldvalue"
                                [value]="radio.id"
                                [(ngModel)]="fieldDefinition.fieldvalue"
                            />
                            {{ radio.value }}
                            <span class="circle">
                                <span class="check"></span>
                            </span>
                        </label>
                    </div>
                    <div *ngIf="ref.errors.required">Поле обязательно для заполнения</div>
                </ng-container>
            </div>
        </ng-container>


Why am I getting this error

Cannot read property 'required'

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question