javascript - Binding using ng-model inside ng-repeat in angularjs -


i'm trying bind model 'user' list of input fields. not know fields beforehand, i've write generic code setup form based on fields.

<script>     function mycontroller($scope){         $scope.fields  = ['name','password','dob'];         $scope.user1 = {name:"shahal",password:"secret"}     }; </script> <div ng-app ng-controller="mycontroller">     <ul>         <li ng-repeat="field in fields">             <label>{{field}}</label><input type="text" ng-model="user1.{{field}}">         </li>     </ul>     <pre>{{fields}}</pre> </div> 

i'm trying loop through fields , show input field each fields (available in scope). binding not proper i'm trying evaluate expression inside ng-model.

basically i'm trying show 3 input fields (name,password,dob) object user1 attached corresponding field.

here's fiddle

any help?

below solve problem

<script>     function mycontroller($scope){         $scope.fields  = ['name','password','dob'];         $scope.user1 = {name:"shahal",password:"secret"}     }; </script> <div ng-app ng-controller="mycontroller">     <ul>         <li ng-repeat="field in fields">             <label>{{field}}</label><input type="text" ng-model="user1[field]">         </li>     </ul>     <pre>{{fields}}</pre> </div> 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -