search

Home  >  Q&A  >  body text

angular.js - Problem with splitting angular2 form into multiple components

Considering issues such as reuse, when a form is split into multiple components, communication issues arise.
Two-way data binding cannot be used in this situation. I thought of the following method, but it is a bit complicated. I would like to ask for a good method.

  1. The parent component passes a submit status value to the child component, and when the submit button is clicked, this value changes.

  2. The subcomponent listens to the submit value through the onChange hook, and when it changes, the bound data inside the subcomponent is sent to the parent component through events.

  3. The parent component listens to the event and gets the binding value of the child component. At this time, it integrates the data and sends the request.

  4. If this situation already exists in some fields, an error value needs to be passed to the sub-component separately and displayed accordingly.

But it’s really troublesome, please ask for help...

PHPzPHPz2755 days ago592

reply all(2)I'll reply

  • 滿天的星座

    滿天的星座2017-05-15 17:07:12

    Components can bind data

    reply
    0
  • 我想大声告诉你

    我想大声告诉你2017-05-15 17:07:12

    When it comes to the dimension of the form, the component particles are already small enough, so splitting them up is not asking for trouble. Only complex UIs need to be encapsulated, such as time selectors, color selectors, etc.

    reply
    0
  • Cancelreply