Rinat Hatipov Rinat Hatipov - 2 months ago 13
AngularJS Question

Angular, how to do list in allert

I want to make a list of people's names in the pop-up window, when you drag the block. I got a list of users, but do not know how to make the list, please help.

My Angular Module and Controller

var app = angular.module('DentalEthereumApp', ['ngMaterial', 'ngDraggable']);
app.controller('MainCtrl', function ($scope) {
$scope.cad_users = [];
var modes = ["doctor","delivery","digitize","cad","mill","patient"];
function guys(mode_index) {
$.ajax({
type:"GET",
url: "/"+modes[mode_index]+"_users",
dataType: 'json',
success: function(result){
$scope.current_guys = result;
alert(JSON.stringify(result));
}
})
};

var mill_users = [];
var design_users = [];
var digitize_users = [];
var doctor_users = [];
var patient_users = [];

$scope.positions = [];
$scope.current_guys = [];
$scope.centerAnchor = true;
$scope.toggleCenterAnchor = function () {
$scope.centerAnchor = !$scope.centerAnchor
}
$scope.Math = Math;
var modes = ["doctor","delivery","digitize","cad","mill","patient"];
$scope.parts = ["doctor","delivery","digitize","cad","mill","patient"];
$scope.angles = [-60,0,60,120,180,240,300];
$scope.centerX_lg = 400;
$scope.centerY_lg = 270;
$scope.radius_lg = 250;
$scope.lists = [[{name: 'Заказ 1'}, {name: 'Заказ 2'},{name: 'Заказ 3'},{name: 'Заказ 4'},{name: 'Заказ 5'},{name: 'Заказ 6'},{name: 'Заказ 7'}],[],[],[],[],[]];
$scope.dropSuccess = function(index,listData,event){
$scope.lists[index].push(listData);
var obj = {data: listData,mode: $scope.parts[index]};
$scope.positions.push(obj);
guys(index);
//!!!!Ethereum action
}
$scope.dragSuccess = function(index,listData,event){
var indexDel= $scope.lists[index].indexOf(listData);
if (indexDel>-1) {
$scope.lists[index].splice(indexDel,1);
}
}


My view, html doc

<div id="contract">
<br><br>
<table width="100%">
<tr ng-repeat="position in positions">
<td>{{position}}</td>
</tr>
</table>
</div>
<div ng-repeat="index in [0,1,2,3,4,5]">
<div style="position:absolute;
width:200px; height:200px; border-radius:10%;
background-color:#CCC;
top: {{centerY_lg+Math.floor(radius_lg*Math.sin(3.14*angles[index]/180))}}px;
left:{{centerX_lg+Math.floor(radius_lg*Math.cos(3.14*angles[index]/180))}}px;
" ng-drop="true" ng-drop-success="dropSuccess(index,$data,$event)">

<h3 style="position:absolute;top:2px;">{{parts[index]}}</h3>

<div class="ng-drag" ng-repeat="listItem in lists[index]" ng-drag="true" ng-drag-data="listItem" ng-drag-success="dragSuccess(index,$data,$event)">
{{listItem.name}}
</div>

</div>
</div>
<div class="contract">
<md-button ng-click="checkBalance()">
Test
</md-button>
</div>


When I drag, I get a pop-up window, but need an ordered list of names

I have this
Thanks.

Answer

Inside the success:

You need to loop trough the results and return only the attributes you need. Here's an example.

var names = "";
result.forEach(function(object, index, array) {
  names =+ " " + object.name;
});

alert(names);