Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free.

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

1 Answer 1

up vote 2 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 at 3:17
    
How do you want the value? –  Arun P Johny Apr 24 at 3:17
    
from dynamically button click –  user944513 Apr 24 at 3:18
    
    
awesome thanks man –  user944513 Apr 24 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.