如何在父组件中为一个子组件元素使用2种不同的ngModel?

时间:2018-07-05 12:10:21

标签: angular typescript angular-module

我有一个带有2个输入文本字段的子组件。我需要将每个它们的 ngModel 传递到父组件中(当然是在一个指令中),并且它们都是必需的,并且必须由 { {1}} 如何实现?有没有一种方法可以起诉 !form.valid

有关[ngModel]="name"文件等的更多详细信息,这里是StackBlitz demo

孩子

*.ts

父母

<mat-form-field>
    <input matInput type="password" 
           name="{{inputNamePass}}" 
           [(ngModel)]="modelPass" 
           (ngModelChange)="modelChange.next($event)" 
           required pattern=".....">
</mat-form-field>
<br><br>
<mat-form-field>
    <input matInput type="password" 
              name="{{inputNamePassConfirm}}" 
              [(ngModel)]="modelPassConfirm" 
              (ngModelChange)="modelChange.next($event)" 
              required>
</mat-form-field>

1 个答案:

答案 0 :(得分:0)

为什么在需要父组件时不使用@Output()和EventEmitter发出输出?

https://angular.io/guide/component-interaction