Search code examples
angularjsui-selectangular-ui-select

associated Angular ui-select


I'm trying to make grouped ui-select, in fact each ui-select option depends on the previous one. for example I have a list of levels in the first UI-select, and then depending on the first ui-select selected Item a list of place number will be displayed on the second ui-select. is that possible? here is my code, but I wasn't yet able to implemnt it :(

<div class="SumoSelect sumo_somename" tabindex="0" style="width:80%">
        <ui-select search-enabled=false ng-model="levelNumber.selected"
                        theme="bootstrap" append-to-body="true" on-select="getListPlacePerLevel(levelNumber.selected)">
                    <ui-select-match placeholder="">{{$select.selected.levelNumber}}</ui-select-match>
                    <ui-select-choices repeat="item in levels">
                    <span ng-bind="item.levelNumber"></span> </ui-select-choices> </ui-select>
    </div>
    <div class="SumoSelect sumo_somename" tabindex="0" style="width:80%; margin-top:20px;">
        <ui-select search-enabled=false ng-model="item.selected"
                        theme="bootstrap" append-to-body="true">
                    <ui-select-match placeholder="">{{$select.selected.item}}</ui-select-match>
                    <ui-select-choices repeat="item in levelNumber.selected.listPlaceNumber">
                    <span ng-bind="item"></span> </ui-select-choices> </ui-select>
    </div>

and my Json data is as below

[{"levelNumber":1,"listPlaceNumber":[1,2,3,4,6]},{"levelNumber":2,"listPlaceNumber":[2,4,6,7]},{"levelNumber":3,"listPlaceNumber":[11,12,13,14,16]}]

Solution

  • See if this plunk works for you:

    http://plnkr.co/edit/2kiQ7W?p=preview

    Relevant Code:

    <div tabindex="0" style="width:80%">
        <ui-select search-enabled="false" ng-model="levelNumber.selected" theme="bootstrap" append-to-body="true" on-select="getListPlacePerLevel(levelNumber.selected)">
            <ui-select-match placeholder="">{{$select.selected.levelNumber}}</ui-select-match>
            <ui-select-choices repeat="item in levels">
                <span ng-bind="item.levelNumber"></span>
            </ui-select-choices>
        </ui-select>
    </div>
    <div tabindex="0" style="width:80%; margin-top:20px;">
        <ui-select search-enabled="false" ng-model="item.selected" theme="bootstrap" append-to-body="true" on-select="getListPlacePerLevel($select.selected)">
            <ui-select-match placeholder="">{{$select.selected}}</ui-select-match>
            <ui-select-choices repeat="item in levelNumber.selected.listPlaceNumber">
                <span ng-bind="item"></span>
            </ui-select-choices>
        </ui-select>
    </div>