Getting form controls from FormController

前端 未结 4 1626
清歌不尽
清歌不尽 2020-12-30 22:48

I need a way to loop through the registered controls of an AngularJS form. Essentially, I\'m trying to get all the $dirty controls, but there\'s no array of the controls (t

4条回答
  •  不思量自难忘°
    2020-12-30 23:07

    I've come up with a somewhat decent solution, but it still isn't what I was looking for. I've salvaged some code from another problem involving creating JSON objects from strings, and come up with the following:

    Essentially I'm naming my fields in the same way they're tied to the model, and then building a new object for submission when the form_submit is called.

    Plnkr demo

    In the demo, if you change either of the form fields, then hit submit, you'll see the object pop up with only the dirty values.

提交回复
热议问题