G
G
GaserV2016-03-28 12:11:09
Angular
GaserV, 2016-03-28 12:11:09

How to use ng-click + ng-show/hide correctly?

There is a DOM (below). I need to implement something like a question-answer, but the answer opens when you click on the question and hides either when you click on the next question. Now the problem is that when you click on a question, all the answers are opened at once, but only for the current question.

<div class="options">		
    <div ng-click="showOptions=!showOptions" class="options-title">Вопрос +</div>
    <div ng-show="showOptions" class="options-content">
      <ul>
        <li><span>ответ</span><span class="icon-edit"></span></li>
        <li><span>ответ</span><span class="icon-edit"></span></li>
      </ul>
    </div>
    <div ng-click="showOptions=!showOptions" class="options-title">Вопрос +</div>
    <div ng-show="showOptions" class="options-content">
      <ul>
        <li><span>ответ</span><span class="icon-edit"></span></li>
        <li><span>ответ</span><span class="icon-edit"></span></li>
      </ul>
    </div>
  </div>

And the second question. Is it possible to somehow animate to be something like jq slideToggle()?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Kravchenko, 2016-03-28
@GaserV

Question-answer pairs are formatted in ng-repeat. By clicking, you change the parameter inside each question, for example, opened. For smoothness, you can use ng-class. Add a class with CSS transition to an open element

N
Nikita Baev, 2016-03-28
@drugoi

Set some unique key to open the elements.
For example:

<div ng-click="showOptions1=!showOptions1" class="options-title">Вопрос +</div>
    <div ng-show="showOptions1" class="options-content">
      <ul>
        <li><span>ответ</span><span class="icon-edit"></span></li>
        <li><span>ответ</span><span class="icon-edit"></span></li>
      </ul>
    </div>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question