Akshay Kumar Akshay Kumar - 5 months ago 43x
Javascript Question

how to get the value of ng-repeat input angularjs?

i created some dynamic input from ng-repeat.

i just want to know, how to get the input value of each dynamically generated input field in html..


<div ng-app="mainApp" ng-controller="mainCtrl">

<div ng-repeat="author in author_group" class="authorAndTagGroup">
<div ng-repeat="(key, value) in author">
<label class="col-sm-3 control-label">{{key}}</label>
<input type="text" value="{{value}}">



var app = angular.module("mainApp", []);
app.controller('mainCtrl', function($scope){

$scope.authors = [{'author_name': 'akshay', 'about_author':'this is about author', 'author_image':'image url here'}];

$scope.author_group = [];

for (var key in $scope.authors) {
$scope.author_group.push({'Author Name' : $scope.authors[key].author_name, 'About the Author' : $scope.authors[key].about_author, 'Author Image' : $scope.authors[key].author_image, 'Author Linkedin Profile' : '', 'Author Twitter Profile' : ''});


Bind your input text to the author object's key'd property works.

<input type="text" ng-model="author[key]">

Note the following as suggested by ebinmanuval does NOT work; this is because it fails to mutate the underlying author object and instead just overwrites the value property. The trick here is that we want to bind the model to a reference type like an object not a value type like a string, that way when we mutate the model the underlying type is mutated as well:

<input type="text" ng-model="value">