mardi 29 janvier 2019

Error: mat-form-field, mat-selection-list must contain a MatFormFieldControl

I am trying to add a checkbox and attach to a formfield. I am using angular 7. I am using tags mat-form-field, and for this I am getting error "ERROR Error: mat-form-field must contain a MatFormFieldControl."

I have checked my Component code and made sure FormControl exist. Though it is not very clear but add formControl "mat-selection-list"

//DECLARE CONTROL
    preexistingControl = new FormControl('',[Validators.required]);
// CHECKBOX DATA
    preExistingCondList: PreExistingCond[] = [
            {id:'0' ,value:'None'},
            {id:'1' ,value:'Arthritis'}, 
            {id:'2' ,value:'Asthma'},];
//ADD TO FormGroup
    preexistingControl:this.preexistingControl,

HTML CODE

<mat-form-field>
            <mat-selection-list #preConditions placeholder="PreExisting Conditions" [formControl]="preexistingControl">
                <mat-list-option *ngFor="let preExistingCond of preExistingCondList">
                                
                </mat-list-option>
            </mat-selection-list>
        </mat-form-field>


It is throwing following error:

ERROR Error: mat-form-field must contain a MatFormFieldControl.
    at getMatFormFieldMissingControlError (form-field.es5.js:119)
    at MatFormField.push../node_modules/@angular/material/esm5/form-field.es5.js.MatFormField._validateControlChild (form-field.es5.js:764)
    at MatFormField.push../node_modules/@angular/material/esm5/form-field.es5.js.MatFormField.ngAfterContentInit (form-field.es5.js:453)
    at callProviderLifecycles (core.js:22311)
    at callElementProvidersLifecycles (core.js:22292)
    at callLifecycleHooksChildrenFirst (core.js:22282)
    at checkAndUpdateView (core.js:23213)
    at callViewAction (core.js:23450)
    at execComponentViewsAction (core.js:23392)
    at checkAndUpdateView (core.js:23215)

I have check the formControl exist and the ref id is correct. Anyone facing this issue please provide an answer.




Aucun commentaire:

Enregistrer un commentaire