angular-cli: Property 'controls' does not exist on type 'AbstractControl'.
Bug Report or Feature Request (mark with an x
)
- [x] bug report -> please search issues before submitting
- [ ] feature request
Versions.
@Angular/cli: 1.0.1 node: 7.5.0 os: win32 x64 Windows (10)
Repro steps.
Running the application using ng serve
works fine.
using ng build
works fine.
when using ng build --prod --aot
or ng build --prod
I get the error.
It points back to this html file and the controls property??
<div formArrayName="Data">
<div class="form-group" *ngFor="let field of form.get('Data').**controls**; let i = index">
<div [formGroupName]="i">
<div class="col-sm-2">
<input type="text" class="form-control input-sm text-right" placeholder="Key" formControlName="Name" />
</div>
<div class="col-sm-6">
<input type="text" class="form-control input-sm" placeholder="Value" formControlName="Data" autocomplete="off" />
</div>
<div class="col-sm-1">
<i class="fa fa-trash-o cursor remove-field" title="Remove field" (click)="removeField(i)"></i>
</div>
</div>
</div>
</div>
The log given by the failure.
ERROR in ng:///C:/Angular/lanes4/src/app/containers/edit-user.component.html (34,13): Property ‘controls’ does exist on type ‘AbstractControl’.
Desired functionality.
I would like to build it using --prod and --aot
Mention any other details that might be useful.
Happened since updating to version 4.0.0, i’ve just been using ng build
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 36
- Comments: 37 (1 by maintainers)
Commits related to this issue
- fix for FormArray access in template https://github.com/angular/angular-cli/issues/6099 — committed to tom-power/gear-inch-calculator by tom-power 7 years ago
- fixed compile issue ERROR in src\app\recipes\recipe-edit\recipe-edit.component.html(65,13): : Property 'controls' does not exist on type 'AbstractControl'. FIX: https://github.com/angular/angular-cli/... — committed to varghesethomas69/myrecipe-book-app by varghesethomas69 6 years ago
- * fixing bug when running ng build --prod: https://github.com/angular/angular-cli/issues/6099 — committed to kcrutcher/benefitsCalculator-angularClient by deleted user 6 years ago
- cambios para poder compilar en produccion https://github.com/angular/angular-cli/issues/6099 — committed to ipartek/java_2018_0554 by anderuraga 5 years ago
Got it!
Looked at the docs - FormArray
The FormArray class contains the
controls
property.get formData() { return <FormArray>this.passwordForm.get('Data'); }
Thanks @Thisen, without you help it would’ve taken longer.
so, my issue was solved by changing the way controls were referenced in my
<md-hint>
blockschanged to
form['controls'].passwords['controls'].confirmPassword.dirty
.can anyone expand one why this is necessary with forms? is it because of the change detection cycle? I find it quite curious that the error was only ocurring on one of my form when the pattern I was using was consistent all forms…
change:
myForm.get('some_items').controls
to:
myForm.get('some_items')['controls'];
worked for me when using
--prod
Can be fixed by giving your component a get method:
get formData { return this.form.get('Data'); }
and then in your template:<div class="form-group" *ngFor="let field of formData.controls; let i = index">
La solucion mas facil es: formGroup.controls[‘any’][‘controls’].
In my case only
ng build --prod --aot
was failing withProperty 'controls' does not exist on type 'AbstractControl'
I changed
to
turns out, its yet another “cast” issue (pun intended) 😉
This problem still present. If use form.get(‘Data’).controls inside *ngFor and run ng build --prod, you will see error: Property ‘controls’ does not exist on type ‘AbstractControl’.
Angular CLI: 1.0.6 Angular: 4.1.3 node: 6.10.3
thnks @zpydee , this solution worked for me: i used myForm[‘controls’].links[‘controls’] instead of myForm.controls.links.controls
What works for me (even using --prod flag) is, instead of using controls in the FormArray I use value:
*ngFor="let item of myForm.get('items').value"
use safe navigation operator
?
change:myForm.get('myField').controls
to:
myForm.get('myField')?.controls
Running Angular 5.2.3 and was having the same problem. I have a nested FormGroup i.e.
I found a few ways to get around this (thanks to y’all posting here). Assuming we have:
We can:
1. Use
.get()
:2. Cast
3. Use a custom class
I ended up going with 1 as I think it’s the cleanest
Спасибо!!! Всё работает!!!
Please reopen the issue still occurs in Angular 5.2.0
CLI doesn’t complain when
['controls']
property accessor is used.Below worked for me
Why is this issue closed? Is this fixed in production builds now? Doesn’t seem like it…
I can confirm this.
when using
--prod
the HTML fails:For now, I’m usin workaround of passing the logic to the
ts
, but it’s not good because it’s a public method.I’m experiencing the same issue when trying to run
ng build --prod
with the snippet below although it seems my circumstance is a bit different. Not seeing this occur on any of my other forms?Can either of your offer any guidance? I’m also running
4.0.0
.Did the same as @leandrodiniz and it also worked with
--env=prod --aot
.