0

Here is my component.ts:

 constructor(
    private fb: FormBuilder,
  ) {}

  formobject = {} as GKCLForm1;
  gkclForm1 = this.fb.group({
    gcklform1 : this.fb.control(this.formobject)
  });

And here the component.html:

<form [formGroup]="gkclForm1">
  <label>
    info:
    <input type="text" formControlName="gcklform1.info">
  </label>

  <label>
    id:
    <input type="text" formControlName="gcklform1.id">
  </label>
</form>

I have an object which type is GKCLForm1. info and id are the properties of that object.

And I want to create a form group from one object is it possible? ( I am using Angular 6 )

3
  • Not sure if it's possible. Why exactly do you want to do this though? Commented Aug 28, 2018 at 15:17
  • Read this: angular.io/guide/reactive-forms to understand Angular Reactive Forms. Commented Aug 28, 2018 at 16:00
  • I tried to make your question easer to understand, but please review my changes, and maybe improve it yourself, too. It is simply hard to grasp what you are asking for. Commented Aug 28, 2018 at 18:54

1 Answer 1

1

Not really sure what it is that you're trying to achieve here. Generally, reactive forms are used so that they could yield a value(generally on submission) that is similar to data model.

There's a difference between primitive type values and complex type values and then there are different AbstractControls used for both the types. If you have a complex type(say an Object), then you should be using a FormGroup for that as well. If you have a primitive type(a string, a number etc), you should be using a FormControl. I'm pretty sure that you won't be able to achieve anything out of it even if you try to use a FormControl for a complex data type.

For your case, I think you should be using a FormGroup for gcklform1.

Here's a StackBlitz for your ref.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.