Join the Stack Overflow Community
Stack Overflow is a community of 6.4 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I am trying to make a simple example in which an input field and a button field each time a user clicks on button.

How can I get the text of the input field when the new button, which is present along with input field, is clicked?

http://codepen.io/anon/pen/yNLGzx

var app = angular.module('ionicApp',['ionic']);
app.controller('cntr',function($scope){
     $scope.addfield=function(){
       alert("how to add input field dyanmically")
     }

})

I don't know how to do this; in jQuery we can use the append function, like so

$('.addcontend').append('<input \> <button>get input value</button>')

How can I acheive this using angularjs?

share|improve this question
up vote 5 down vote accepted

What you can do is to use an array to represent the inputs then loop through the array and render it like

 <div class="addcontend">
   <div ng-repeat="item in inputs">
     <input ng-model="item.value"\> <button>get input value</button>
   </div>
  </div>

then

  $scope.inputs = [];
  $scope.addfield=function(){
    $scope.inputs.push({})
  }

Demo: CodePen

share|improve this answer
    
thanks for answer but how to get value of input field which is generated dynamically from dynamically generated button – user944513 Apr 24 '15 at 3:17
    
How do you want the value? – Arun P Johny Apr 24 '15 at 3:17
    
from dynamically button click – user944513 Apr 24 '15 at 3:18
1  
see jsfiddle.net/arunpjohny/a92hnfmk/2 – Arun P Johny Apr 24 '15 at 3:20
    
awesome thanks man – user944513 Apr 24 '15 at 3:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.