You can't do that, I mean when you want to using formControlName
, then you should have to put it inside [formGroup]="formGroup"
section.
For an example, you only can do something like this code below:
<form [formGroup]="form">
<ng-container *ngIf="true; then fooSection"></ng-container>
<ng-template #fooSection>
<input type="checkbox" formControlName="isEulaAccepted">
<ng-template>
</form>
Update: Or you can do this, if you want to put outside [formGroup]
section.
In your typescript, you can do add this:
public get isEulaAccepted(): FormControl {
return this.formGroup.get('isEulaAccepted') as FormControl;
}
Or if you only have one formControl
, so you should not have to using formGroup
, just using formControl
like this:
public isEulaAccepted: FormControl = new FormControl(null);
And, in your html, you can use this one:
<ng-container *ngIf="true; then fooSection"></ng-container>
<ng-template #fooSection>
<input type="checkbox" [formControl]="isEulaAccepted" />
<ng-template></ng-template
></ng-template>
Now, it will working fine.