1

因为我在模板表单中使用了几个类似的 mat-inputs,所以我为这些 mat-inputs 定义了一个 ng-template 并通过引用它*ngTemplateOutlet并将相关数据传递给模板,如下所示:

<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>

但我收到了这个错误:

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

如何解决这个问题?此致

4

0 回答 0