我有两个自定义输入,如下所示:
<custom-input [name]="'lastName'" [customErrorMessage]="errorMessage" (valueChange)="lastNameChange($event)">
</custom-input>
<custom-input [name]="'firstName'" [customErrorMessage]="errorMessage" (valueChange)="firstNameChange($event)">
</custom-input>
errorMessage
名字和姓氏。
它工作得很好,也就是说,当我更改名字时,只会出现名字错误,姓氏也会出现同样的错误。虽然它指向的是同一个变量,但它似乎工作得很好。
有没有这种方法行不通的情况?
以下是自定义输入组件的代码:
@Component({
selector: 'custom-input',
templateUrl: './input.component.html',
styleUrls: ['./input.component.scss'],
providers: [MyService]
})
export class InputComponent extends FormComponent implements OnInit, OnChanges, AfterViewChecked, AfterViewInit, OnDestroy {
@Input() customErrorMessage;
}