在formGroup中获取表单ID

问题描述 投票:0回答:1

我正式使用ngx来构建表单。我需要的是访问我拥有的某些自定义类型内的表单ID。基本上,我需要访问formGroup中的表单ID。

HTML

   <div>
        <form [formGroup]="form" [id]="formId">
            <formly-form [form]="form" [model]="model" [fields]="fields" [options]="options"></formly-form>
        </form>
    </div>

。ts

 formId = "unique_id_from_backend"
 form = new FormGroup({});

输入类型组件

@Component({
    selector: 'input-field',
    templateUrl: './input.html',
})
export class InputFieldComponent extends FieldType implements OnInit {

    ngOnInit(): void {
        console.log(this.form);
        // here i can access formGroup that i am passing in <form> but it seems id property is 
        // not there. Is there some way i can access form id?
    }

}
angular typescript forms angular-reactive-forms ngx-formly
1个回答
1
投票

在自定义字段类型中,您可以访问字段和选项实例,可以在其中获取ID,键...

© www.soinside.com 2019 - 2024. All rights reserved.