Arter Arter - 12 days ago 9
AngularJS Question

angularjs xeditable - ng-options

i have problem with getting id from selected distributor. Here is my html code for select distributor

<span editable-select="currentKlupa.distributor" e-form="tableform" e-ng-options="user as user for user in getAllUserFromRolesPushano">{{::currentKlupa.distributor.username}}
</span>


I also have another select box, and all working correct, but this one not, because i need get id from this select.

here is controller

$scope.getUserFromRoles = function (rolaProslijedena) {
$scope.getAllUserFromRolesPushano = [];
$scope.getAllUserFromRoles = dohvacanjeUseraPoRolama.get({rola: rolaProslijedena});
$scope.getAllUserFromRoles.$promise.then(function (data) {
angular.forEach(data.users, function (key, value){
$scope.getAllUserFromRolesPushano.push(key.username);
});

});
};


I need to get id from this selected distributor, how to set ng-options for this? Thnx

Answer

Without more informations, I give you an example with a tricks (i haven't found a better solution yet):

I have a Show done by an artist.

$scope.shows = {artist_id : 4};

and a list of artists.

$scope.artists = [{id : 1, name : 'artist1'},{id : 2, name : 'artist2'},...];

my html will be:

<span editable-select="shows.artist_id" e-name="name" e-form="rowform"  e-ng-options="g._id as g.name for g in artists">
    {{DisplayName(shows)}}
</span>

The trick is the use of DisplayName.

$scope.DisplayName= function(item) {
  var selected = $scope.artists.filter(function( obj ) {return (obj._id == item.artist_id)})[0]
  return selected.name;
};

This is really not the best solution but that works.