Answer the question
In order to leave comments, you need to log in
Angular 6 ng build --prod error Argument of type 'AbstractControl' is not assignable to parameter of type 'FormControl'?
Hello. There is a simple form that angular cli swears at
<form [formGroup]="formResend" (ngSubmit)="forgot()" class="form">
<input type="email" formControlName="email" [(ngModel)]="model.email" appDebounce (onDebounce)="setErrorMessage(formResend.controls['email'])" placeholder="Email">
<button type="submit" [disabled]="!formResend.valid" >Submit</button>
</form>
ng build --prod
Error
when executing commandERROR in src\app\signin\signin.component.html(14,92): : Argument of type 'AbstractControl' is not assignable to parameter of type 'FormControl'.
Property 'registerOnChange' is missing in type 'AbstractControl'.
src\app\signin\signin.component.html(21,102): : Argument of type 'AbstractControl' is not assignable to parameter of type 'FormControl'.
(onDebounce)="setErrorMessage(formResend.controls['email'])"
onDebounce
import { Directive, Input, Output, EventEmitter, OnInit, OnDestroy } from '@angular/core';
import { NgControl } from '@angular/forms';
import { Subject } from 'rxjs';
import 'rxjs/add/operator/debounceTime';
import 'rxjs/add/operator/distinctUntilChanged';
import 'rxjs/add/operator/takeUntil';
@Directive({
selector: '[ngModel][appDebounce]'
})
export class DebounceDirective implements OnInit, OnDestroy {
@Output()
public onDebounce = new EventEmitter<any>();
@Input('debounce')
public debounceTime: number = 500;
private ngUnsubscribe: Subject<void> = new Subject<void>();
constructor(public model: NgControl) {
}
ngOnInit() {
this.model.valueChanges
.takeUntil(this.ngUnsubscribe)
.debounceTime(this.debounceTime)
.distinctUntilChanged()
.subscribe(modelValue => {
this.onDebounce.emit(modelValue);
});
}
ngOnDestroy() {
this.ngUnsubscribe.next();
this.ngUnsubscribe.complete();
}
}
Answer the question
In order to leave comments, you need to log in
Make a getter in the component
get formResendEmail() {
return formResend.controls['email'] as FormControl
}
(click)="setErrorMessage(formResendEmail)"
public toFormControl(point: AbstractControl): FormControl {
return point as FormControl;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question