I have a backend REST service that returns an array. I am trying to display the value returned by this REST service in one of my <select>
using ng-options
. However I get [object Object]
on the lists.
Backend Java Rest service
@Path("/positions")
public class PositionRestService {
ManagerService managerService = new ManagerService();
@GET
@Produces(MediaType.APPLICATION_JSON)
public List<String> getVacantPositions(@HeaderParam("iv-user") String uid) throws Exception{
Manager manager = managerService.getManager(uid);
LdapSearch ldapProfile = new LdapSearch();
List<String> vacantPositions = new ArrayList<String>();
vacantPositions = ldapProfile.getChildPositions(manager.getPositionID());
return vacantPositions;
}
}
AngularJS Code - Service.js
services.factory('PositionsFactory', function ($resource) {
return $resource('/userfeed/rest/positions', {}, {
query: { method: 'GET', isArray: true}
})
});
AngularJS - Controller.js
app.controller('PositionCtrl', ['$scope', 'PositionsFactory', function ($scope, PositionsFactory) {
//$scope.positions = PositionsFactory.query();
PositionsFactory.query({}, function (positionsFactory) {
$scope.positions = positionsFactory;
})
}]);
My HTML code that uses the controller
<select ng-model="myPosition" ng-options="position as position for position in positions"> </select>
Result I seee the follwing options on my list of options.
[object Object]
When I access the REST Service using my browser, I get the following array result which is what I am expecting on my option box above.
["CU13-00-00-004-","CU13-00-00-005-","CU13-00-00-006-"]
How can I get the values CU13-00-00-004-, CU13-00-00-005- and CU13-00-00-006-
on my options using ng-options
.
On using
{{positions|json}}, I get following outcome:
[
{ "0": "C", "1": "U", "2": "1", "3": "3", "4": "-", "5": "0", "6": "0", "7": "-", "8": "0", "9": "0", "10": "-", "11": "0", "12": "0", "13": "4", "14": "-" }, { "0": "C", "1": "U", "2": "1", "3": "3", "4": "-", "5": "0", "6": "0", "7": "-", "8": "0", "9": "0", "10": "-", "11": "0", "12": "0", "13": "5", "14": "-" }, { "0": "C", "1": "U", "2": "1", "3": "3", "4": "-", "5": "0", "6": "0", "7": "-", "8": "0", "9": "0", "10": "-", "11": "0", "12": "0", "13": "6", "14": "-" } ]
Looks like it has converted the array into JSON object and created a place holder for earch character. The with ng-options show them as [object Object].
Please help. Any suggestion would be much appreciated.