1

since I use several similar mat-inputs inside a template form, I define an ng-template for these mat-inputs and refer to it via *ngTemplateOutlet and also pass related data to the template as bellow:

<ng-template #formFieldInput let-hintMsg="hintMsg" let-lable="lable" let-        dataBinding="dataBinding">
  <mat-form-field appearance="outline" class="fa">
    <mat-label>{{lable}}</mat-label>
    <input matInput type="text"  name="nationalCode"
        [(ngModel)]="dataBinding" [disabled]="!personalInfoEdit"/>
    <mat-hint *ngIf="personalInfoEdit">{{hintMsg}}</mat-hint>
  </mat-form-field>
</ng-template>

// ... 

<ng-container *ngTemplateOutlet="formFieldInput; context:{hintMsg: 'Enter National Code', lable: 'National Code', dataBinding: profileDetails.nationalCode} ">
</ng-container>

but I got this error:

 [webpack-dev-middleware] Error: Cannot assign value "$event" to template variable "dataBinding". Template variables are read-only.

how can fix this problem? best regards

1
  • As I know it's not possible to bind variables that way. All I can suggest it's to create a separate component for the template. Commented Jan 29, 2022 at 18:53

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.