简体   繁体   English

属性'xxxx'不存在于类型'{{键:字符串]:AbstractControl; }”

[英]Property 'xxxx' does not exist on type '{ [key: string]: AbstractControl; }'

import { FormGroup } from '@angular/forms';

export class MasterVendorFormContactComponent implements OnInit {
  @Input() formContactGroup: FormGroup;
// rest of the code 
}


<fieldset [formGroup]="formContactGroup" class="master-vendor-form-contact">
  <md-input-container class="master-vendor-form-contact__phone"
                      [dividerColor]="formContactGroup.controls.phone?.valid ? 'default' : 'warn'">
    <input mdInput placeholder="Enter phone" formControlName="phone">
    <md-hint align="end"
             *ngIf="!formContactGroup.controls.phone?.valid">
      Vendor phone number must be in (XXX) XXX-XXXX format
    </md-hint>
  </md-input-container>
  <!-- Rest of the code -->
</fieldset>

on compiling this code with aot it gives following error: 用aot编译此代码时,会出现以下错误:

angular_app/src/$$_gendir/app/master-vendors/master-vendor-form-contact/master-vendor-form-contact.component.ngfactory.ts (465,73): Property 'phone' does not exist on type '{ [key: string]: AbstractControl; }'.
angular_app/src/$$_gendir/app/master-vendors/master-vendor-form-contact/master-vendor-form-contact.component.ngfactory.ts (465,143): Property 'phone' does not exist on type '{ [key: string]: AbstractControl; }'.
angular_app/src/$$_gendir/app/master-vendors/master-vendor-form-contact/master-vendor-form-contact.component.ngfactory.ts (476,77): Property 'phone' does not exist on type '{ [key: string]: AbstractControl; }'.
angular_app/src/$$_gendir/app/master-vendors/master-vendor-form-contact/master-vendor-form-contact.component.ngfactory.ts (476,147): Property 'phone' does not exist on type '{ [key: string]: AbstractControl; }'.

I tried following this approach: 我尝试了以下方法:

Don't use form.controls.controlName, use form.get('controlName') 不要使用form.controls.controlName,请使用form.get('controlName')

but here I have formContactGroup so it seems not working for me. 但这里我有formContactGroup,所以它似乎对我不起作用。

There are two options, you can update to the latest typescript version. 有两个选项,您可以更新到最新的打字稿版本。 Since version 2.2 they allow the dot notation for types with string index signatures. 2.2版开始,它们允许带有字符串索引签名的类型使用点符号。

Or you can change your template, which makes more sense because that's the proper way to do it :) documentation : 或者您可以更改模板,这更有意义,因为这是执行模板的正确方法:) 文档

<md-input-container [dividerColor]="formContactGroup.get('phone').valid ? 'default' : 'warn'">

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 属性 ... 不存在于类型 &#39;{ [key: string]: AbstractControl; }&#39; - Property … does not exist on type ‘{ [key: string]: AbstractControl; }’ 类型“ AbstractControl”上不存在属性“控件”。 角度7 - Property 'controls' does not exist on type 'AbstractControl'. Angular 7 &#39;AbstractControl&#39; 类型不存在属性 &#39;controls&#39;。” - Property 'controls' does not exist on type 'AbstractControl'." 获取错误“属性”…“在“AbstractControl”类型上不存在 - Getting error 'Property '…' does not exist on type 'AbstractControl' Angular 4:属性“push”和“controls”在“AbstractControl”类型上不存在 - Angular 4: Property “push” and “controls” does not exist on type “AbstractControl” Angular 2 build --prod失败“类型&#39;AbstractControl&#39;上不存在属性&#39;controls&#39;” - Angular 2 build --prod fails “Property 'controls' does not exist on type 'AbstractControl'” Angular 5 - 模板错误:“AbstractControl”类型中不存在“属性&#39;长度&#39;” - Angular 5 - Error on template: “Property 'length' does not exist on type 'AbstractControl'” 嵌套反应式表单中的错误 - 类型“AbstractControl”上不存在属性“控件” - Error in Nested Reactive Forms - Property 'controls' does not exist on type 'AbstractControl' Angular AOT编译错误:类型&#39;AbstractControl&#39;上不存在属性&#39;length&#39; - Angular AOT compilation error: Property 'length' does not exist on type 'AbstractControl' 类型“AbstractControl”上不存在属性“controls” - angular4 - Property 'controls' does not exist on type 'AbstractControl' - angular4
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM