Abhijars Abhijars - 1 month ago 9
AngularJS Question

How to append object field value as string in textarea on clicking particular object field using angular js

i want to append object value to textarea on clicking on particular object field of ng-repeat. http://jsfiddle.net/kkd5nhev/

<div ng-repeat="list in listing">
<a href="">{{list.name}}</a>
</div>
<br>




var myApp = angular.module('myApp', []);

myApp.controller('Main', function($scope){

$scope.listing = [{id :"1", name:"one"},{id :"2", name:"two"},{id :"3", name:"three"}];
$scope.complaint = "";


});

Answer

Create a function to do the adding in your controller, for example:

$scope.addToTextArea = function(item) {
    var newline = String.fromCharCode(13, 10);
    $scope.complaint += item.name + newline;
}

and hook into this using the ng-click directive:

<a href="" ng-click="addToTextArea(list)">{{list.name}}</a>
Comments