Sreehari S Sreehari S - 1 year ago 130
AngularJS Question

AngularJS : Display a property value of multiple objects in an input text field, comma separated

I have an array of JSON objects in the format


I need to display the names of all users in an
input text field
comma separated as below image.

enter image description here

I tried using
directive, but for that I had to first loop through the user objects and store all the names in a separate array and use that array as
for the
element. Is there an easy, alternate way in angularjs?

Answer Source

A simple JS solution Use Map function to get the desired property in array then use a join over it

 var users=[{id:'1',name:'ABC'},{id:'2',name:'DEF'}];

 $scope.userModel ={return}).join(",");

 <input type="text" ng-model="userModel">
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download