I need to hide a drop-down list when the model is empty and to show it when there are values in the model.
I have a service to get the values.
angular.module('myApp.services', ['ngResource']) .factory('OptionsSelect', ['$resource', function ($resource) { return $resource('http://myapi/miapp/optionselect/1', {}, { query: { method: 'GET', params: { id: '1' }, isArray: false } }); } ])The possible result is:
{"1":"red","5":"blue","34":"blue"}
or
<pre>
{}
</pre>
In the controller:
$scope.optionsSelect = OptionsSelect.query();
The view is:
<div class="form-group" ng-hide="isHide()"> <select class="form-control" ng-options="key as value for (key, value) in optionsSelect"> </div>You can view the code in jsfiddle: http://jsfiddle.net/finsi/LMJXC/38/
isArray: true), but your result is not an array, it's just an object. That's going to cause an error.