Property 'controls' does not exist on type 'AbstractControl'
See original GitHub issueI’m submitting a
[x] bug report
Current behavior
As there’s no clean access to the FormGroup’ controls, currently there’s a ng build -prod error related to types when you try to access the .controls property, and AbstractControl does not have that property:
ERROR in ng:///path/to/app/my/custom.component.html (7,10): Property 'controls' does not exist on type 'AbstractControl'.
https://github.com/angular/angular/blob/4.0.0/packages/forms/src/model.ts#L834
where I have a form with subgroups like:
this.inputForm = this._builder.group({
base: this._builder.group({
monthly: [
'', Validators.compose([Validators.required, Validators.pattern(regInt)])
],
...
}),
user: this._builder.group({
...
})
});
and perform template-driven validations per row like:
<div class="form-group row" [ngClass]="{'has-danger': inputForm.controls.base.controls.monthly.dirty && !inputForm.controls.base.controls.monthly.valid}">
<label class="col-4 col-form-label" for="inp-monthly">
Monthly Expenses
</label>
<div class="col-8">
<div class="input-group">
<span class="input-group-addon" id="inp-monthly-s">$</span>
<input class="form-control" id="inp-monthly" formControlName="monthly" aria-describedby="inp-monthly-s"
type="number" min="1" placeholder="Add up all your costs (rent, salary, telephone, internet, inventory costs, etc)" />
</div>
<div class="form-control-feedback" [hidden]="inputForm.controls.base.controls.monthly.pristine || inputForm.controls.base.controls.monthly.valid">
Please enter a quantity.
</div>
</div>
</div>
Expected behavior
ng build -prodto compile without Type errors.
Minimal reproduction of the problem with instructions References to this issue are in this ticket: https://github.com/angular/angular/issues/10192#issuecomment-264246375
- Angular version: 4.0.1 Project built with angular/cli 4.0.0 but packages updated today to 4.0.1
Issue Analytics
- State:
- Created 6 years ago
- Comments:16 (2 by maintainers)
Top Results From Across the Web
Property 'controls' does not exist on type 'AbstractControl ...
Based on @Günter Zöchbauer comments , first i changed. myForm.controls['addresses'] to myForm.get('addresses') in both html and typescript.
Read more >Property 'controls' does not exist on type 'AbstractControl'. #6099
This problem still present. If use form.get('Data').controls inside *ngFor and run ng build --prod, you will see error: Property 'controls ...
Read more >Property 'at' does not exist on type 'AbstractControl - Telerik
1 Answer, 1 is accepted ; kendo-grid-column field="ProductName" title="Product Name" width="250"> ; ng-template kendoGridCellTemplate let-dataItem ...
Read more >Property 'controls' does not exist on type 'AbstractControl'. in ...
Coding example for the question Property 'controls' does not exist on type 'AbstractControl'. in angular 8-angular.js.
Read more >angular/angular - Gitter
Property 'controls' does not exist on type 'AbstractControl'. angular-tslint says i cant use form.get('contactDetails').get('firstName') ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@matheo thanks.
FormGroup.controlsreturn type is{[key: string]: AbstractControl}.inputForm.controls.basewill returnAbstractControl. This is why you got an error.as a workaround use
getmethod:inputForm.get('base.monthly').pristineI have nested arrays in the same forms, this doesn’t work from me . why it should run on dev and after 2 weeks of development we get this error ?