Create Form with Components at Angular 2

Asked

Viewed 483 times

2

I’m starting with Angular 2 and I have a question, I believe simple, in the creation of forms:

For example in a system that contains the following entries:

  • Customers
  • Suppliers
  • Carriers

Each registration will have its respective fields and will also have shared fields as for example the address fields. For this I could create a Component and use it in the respective forms? What would be the sending of these forms to the class objects using Reactive Form? This is the right thing to do, or should I recreate the address fields in each form?

  • 1

    I haven’t used Reactiveforms yet, but usually if you have fields or a portion of code that will be replicated constantly is already a strong indication that componentization can be applied, in your address case, I think it applies very well a standard Component to treat address.

  • 1

    Okay, I’m still a little confused about sending the form data to the class Typescript, whether to create several Forms to be sent by the click event or a single form containing the Component <app-address> for example.

  • 2

    You can create an <app-address> with a @Output by returning an Emit to the parent typescript ... from a look at @Output()

  • @Gabrielberlanda I think this might help you data pass this link has an example where you share data between components I think this can help you.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.