ihemant360 ihemant360 - 2 years ago 72
AngularJS Question

Angularjs : i want to insert value to input field on click

<input type='text' ng-model="mydata" />
<span ng-bind="$parent.$eval(mydata)"></span> <br>

<button ng-repeat="button in buttons" ng-click =" mydata = button">

Here i have array of buttons and when i click one button it will be inserted in input field without removing previous value.

Answer Source

Problem is that ng-repeat creates new scope. You need to do ng-click="$parent.mydata=button"

check it out here: http://plnkr.co/edit/yrIR6L0tDBI1IaCkaKYw?p=preview

<div ng-controller="Ctrl">
    <input type='text' ng-model="mydata"  />
    <button ng-repeat="button in buttons" ng-click="$parent.mydata = $parent.mydata.toString() + button">{{button}}</button>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download