Andrei Dziashko Andrei Dziashko - 1 year ago 40
AngularJS Question

How to obtain values from input fields with Angular JS after ng-repeat

I'm new in AngulsrJS and I've got following code:

<form ng-if="editorCtrl.edit" class="form-horizontal" role="form" ng-submit="editorCtrl.saveEntry()">
<div class="form-group">
<div class="col-md-6" ng-repeat="(key,field) in editorCtrl.editEntry">
<input type="text" class="form-control" value={{field}} />
<!-- ng-model="editorCtrl.toSave[key]" ng-value="{{field}}" that part was in input attributes -->
<div class="form-group">
<div style="padding-left:110px">
<input type="submit" value="Update selected entry" ng-disabled="form.$invalid" class="btn btn-primary"/>


Now I need to obtain values from input fields. I tried to use ng-model="editorCtrl.toSave[key], but it's not working in a correct way.

Any suggestions how to resolve this situation ?

Answer Source

if you can consider no necesary the "toSave" object maybe you can use the 2-way data binding properly only using editEntry Object :

<input type="text" class="form-control" value={{field}} ng-model="editorCtrl.editEntry[key]"/>

In this way after a submit you will get editEntry with the fields modifieds (or not), here is an example

run the example and if you modified the fields after you press the submit button it will be displayed in your browser console

hope this help ! and sorry for my english !

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download