K
K
KOPC18862014-11-25 16:50:42
Angular
KOPC1886, 2014-11-25 16:50:42

How to hide/show a block depending on the selected list item?

Hello!
Tell me how to make it so that if you select the value "yes", then the block is shown, and if "no", then it is hidden?
Here is the html

<div class="new_service auto">
                                <label for="autoAppl">Список заявок</label>
                                <select id="autoAppl" class="form-control auto_applications">
                                    <option class="auto" value="Y">Да</option>
                                    <option class="auto" value="N" selected>Нет</option>
                                </select>
                            </div>
                            <div class="new_service applications" ng-show="">
                                <label for="listApplications">Список заявок</label>
                                <select id="listApplications" class="form-control list_applications">
                                    <option class="application" value="{{app.id}}" ng-repeat="app in applications">{{app.name}}</option>
                                </select>
                            </div>

I know how to do it through JQuery, but how through Angular?
It is necessary that the new_service applications block be hidden / shown depending on the selected value of the auto_applications list

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nikita Gushchin, 2014-11-25
@iNikNik

Add ngModel to the select:

<select id="autoAppl" class="form-control auto_applications" ng-model="autoApplications">
    <option class="auto" value="Y">Да</option>
    <option class="auto" value="N" selected>Нет</option>
</select>

And for add ngShow:
<div class="new_service applications" ng-show="autoApplications == 'Y'">

_
_ _, 2014-11-25
@AMar4enko

Don't use ng-repeat for options inside select, that's what ng-options is for.

$scope.yesNoOptions = [
    {value: 'Y', title: 'Да'},
    {value: 'N', title: 'Нет'}
];
$scope.applications = [
    {id: 1, title:  'Application title', ...},
    ...
];

<select id="autoAppl" class="form-control auto_applications" ng-model="autoApplication" ng-options="opt.value as opt.title for opt in yesNoOptions">
</select>
<div class="new_service applications" ng-show="autoApplication == 'Y'">
    <label for="listApplications">Список заявок</label>
    <select id="listApplications" class="form-control list_applications" ng-options="app.id as app.title for app in applications">
    </select>
</div>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question