I have 2 dropdowns and a button that triggers a function. The goal is to execute different parts of the code based on whether a location or an assigned item is selected. It even works if both are null in the API, allowing for one selection to be changed.
$scope.edit_location = function() {
for(var i = 0; i < $scope.inventories.length; i++) {
if($scope.currentInventory.location){
console.log('I am in location');
var copySelectedInv = Restangular.copy($scope.currentInventory);
copySelectedInv.customPUT({location: $scope.currentInventory.location, assigned: null, tags: $scope.inventories[i].tags});
}else if ($scope.currentInventory.assigned){
console.log('I am in assigned');
var copySelectedInv2 = Restangular.copy($scope.currentInventory);
copySelectedInv2.customPUT({location: null, assigned: $scope.currentInventory.assigned, tags: $scope.inventories[i].tags});
}
}
};
Dropdown options in my template
<select class="input-medium form-control" ng-model="currentInventory.location">
<option value="">Choose location</option>
<option value="{{location.resource_uri}}" ng-repeat="location in locations">{{location.name}}</option>
</select>
<h5>Assign to employee</h5>
<select class="input-medium form-control" ng-model="currentInventory.assigned">
<option value="">Choose location</option>
<option value="{{user.resource_uri}}" ng-repeat="user in users">{{user.first_name + ' ' + user.last_name}}</option>
</select>
<button class="btn tbn-lg btn-success" ng-click="edit_location()">