Ok, that worked for me.
var propertiesSearchModule = angular.module('propertiesSearchModule'); propertiesSearchModule.controller('searchFormController', ['$scope' ,'$rootScope', function($scope, $rootScope) { $scope.a = [ {label:'Sale', value:'sale'}, {label:'Rent', value:'rent'} ]; $scope.t = { residential : { label:'Residential', value:'residential', uOptions : [ {label: 'Villa', value: 'villa'}, {label: 'Apartment', value: 'apartment'}, {label: 'Duplex', value: 'duplex'}, {label: 'Office', value: 'office'} ] }, commercial : { label:'Commercial', value:'commercial', uOptions :[ {label: 'Penthouse', value: 'penthouse'}, {label: 'Full floor', value: 'full floor'}, {label: 'Hotel apartment', value: 'hotel apartment'}, {label: 'Warehouse', value: 'warehouse'} ] } } }]);
And here is the HTML
<div data-ng-controller="searchFormController"> <form name="propertiesSearchForm" action="" method="get"> <select name="t" id="select-type" class="search-select" data-ng-options="v.value as v.label for (x,v) in t" data-ng-model="fields.t"> <option value="" selected="selected">Types</option> </select> <select name="u" id="select-unit-type" data-ng-options="y.value as y.label for y in t[fields.t].uOptions" data-ng-model="fields.u"> <option value="" selected="selected">Unit Type</option> </select> </form> </div>
Inspired by: http://jsfiddle.net/annavester/Zd6uX/
source share