Property 'controls' does not exist on type 'AbstractControl'

See original GitHub issue

I’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:closed
  • Created 6 years ago
  • Comments:16 (2 by maintainers)

github_iconTop GitHub Comments

29reactions
DzmitryShylovichcommented, Apr 3, 2017

@matheo thanks. FormGroup.controls return type is {[key: string]: AbstractControl}. inputForm.controls.base will return AbstractControl. This is why you got an error.

as a workaround use get method: inputForm.get('base.monthly').pristine

12reactions
almgwarycommented, Dec 1, 2017

I 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 ?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found