Ahmad Saad
Ahmad Saad

Reputation: 803

how to bind dynamic generated inputs to $scope

I am retrieving items from db put them in dir-paginate or ng-repeat what i am trying here to pass id in as model name to get key and name also as key as i am fetching a array to create many inputs and retrieve them in controller, but when i retrieve ng-model object values with console.log($scope.values); it says undefined. how i will pass multiple generated inputs to controller in scope object is my question even ng-click dont work ?? view

<form angular-validator-submit="submitForm()"
    name="submit-form" class="form-horizontal" novalidate
    angular-validator>
    <table>
    <thead>
    <tr>
    <th>S.No</th>
    <th>id</th>
    <th>Name</th>
    </tr>
    </thead>
    <tbody>
    <tr dir-paginate="x in items| itemsPerPage: pageSize" current-page="currentPage">
        <td><input type="text" name="id" ng-model="values.{{x.id}}[$index]"></td>
        <td><input type="text" name="test" ng-model="values.{{x.name}}[$index]"></td>
        </tr>
        </tbody>
        </table>
        <button type="submit" class="btn btn-primary">Save</button>
    </form>

        $scope.submitform = function(){
        console.log($scope.values);
    }

Upvotes: 1

Views: 57

Answers (1)

ask-dev-345
ask-dev-345

Reputation: 22

ng-model="values[x.id]" will do the work and define $scope.values = []; as suggested in comments.

Upvotes: 1

Related Questions