0

I have created dynamic form, here I want to send form data to controller. How can do this?

Here is plunker code link https://plnkr.co/edit/xmxDJHTPfJoSFwa2FWCB?p=preview

Issues:

  1. when I change the value then element label also change.
  2. How can I get the form data in product_submit function of controller.

All response appreciated.

3
  • For answer to your 1 you use the same variable as label name and as input value that's why there's the same value Commented May 27, 2016 at 8:49
  • Yes I know that but here I want form data with same name in controller because names are dynamic so I want values in Controller with same name. Commented May 27, 2016 at 8:56
  • Can I get these values in controller in new array with same name index? Commented May 27, 2016 at 8:59

2 Answers 2

1

Use

<input type="text" 
       id="module_module" 
       ng-model="getCol.value" 
       required="required" 
       class="form-control col-md-7 col-xs-12" 
       placeholder="Enter {{getCol.Field}}"

/>

Look here ng-model="getCol.value". You are using filed name as text field model value. Filed name and value are different. That is what you want I suppose.

You can access the values easily from your controller as $scope.getColumn[1].value. Change index or iterate accordingly.

Plunker here

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

3 Comments

But How can I get value in controller with associated variable name?
In your controller it is already on your getColumn array. This array holds objects. Each object has a value, just like your Field property. You can iterate over the array or directly access with index as $scope.getColumn[1].value.
I am getting error, please help me to change in plunker what you said.
0
  1. To solve label issues, in your html, I changed ng-model expression to bound into getColumn.Value

  2. In controller, I can read value entered in scope.getColumn[i].Value

I also updated code https://plnkr.co/edit/KlhAb69seMzHsLuhqweR?p=preview

2 Comments

This array already present in controller. I can get that. but Here I need to get edited value associated with variable name
Because you use getColumn.Field for your ng-model. I update my answer and code. Pls look at it again.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.