0

Code:

<div class="input-dropdown-wrapper d-flex space-between vertical-center margin-right-12"
                             ng-class="{'active': historyController.showFilterHistoryDurationDropdown === true}"
                             ng-click="historyController.showFilterHistoryDurationDropdown = true"
                             when-clicked-off="historyController.showFilterHistoryDurationDropdown = false">
                            <p>
                                Show {{historyController.filter}}
                            </p>
                            <i class="fas fa-angle-down"></i>
                            <ul class="input-dropdown"
                                ng-if="historyController.showFilterHistoryDurationDropdown">
                                <li ng-class="{'active': historyController.filter === 'All'}"
                                    ng-click="historyController.filter = 'All';
                                    historyController.showFilterHistoryDurationDropdown = false">
                                    Show All
                                </li>
                                <li ng-class="{'active': historyController.filter === 'In Progress'}"
                                    ng-click="historyController.filter = 'In Progress';
                                    historyController.showFilterHistoryDurationDropdown = false">
                                    Show In Progress
                                </li>
                                <li ng-class="{'active': historyController.filter === 'Completed'}"
                                    ng-click="historyController.filter = 'Completed';
                                    historyController.showFilterHistoryDurationDropdown = false">
                                    Show Completed
                                </li>
                            </ul>
                        </div>

All of this works perfectly. When the <div class="input-dropdown-wrapper...> gets clicked, the <ul> appears as it should.

What I don't understand is why the second part of the ng-click of each <li> doesn't work at all.

Specifically talking about this part: historyController.showFilterHistoryDurationDropdown = false".

Setting this value to false should hide the <ul>, just like when you click the <div>, it sets the value to true, causing the <ul> to appear.

6
  • try replacing ng-if with ng-show Commented Jun 19, 2018 at 6:42
  • Best approach for multi line functionalities is, create a method in ur controller and just use the function in ng-click. Commented Jun 19, 2018 at 6:44
  • @YousafHassan that doesn't seem to make any difference. Commented Jun 19, 2018 at 6:47
  • Just curious...if you remove the line before historyController.showFilterHistoryDurationDropdown = false" (so that this expression is the only one in the ng-click), does it work? If not, then it's not an issue with having multiple expressions. Commented Jun 19, 2018 at 6:51
  • @AndroidNoobie interestingly no, keeping that expression as the only one inside the ng-click does not work at all. Commented Jun 19, 2018 at 7:01

1 Answer 1

1

If you are looking for some Toggle view solution, ng-click logic should toggle the showFilterHistoryDurationDropdown value Like :

ng-click="historyController.showFilterHistoryDurationDropdown
          ? historyController.showFilterHistoryDurationDropdown = false
          : historyController.showFilterHistoryDurationDropdown = true"

So that when you click on the div having the ng-class will show the list (<ul>), on second click it will hide the list (<ul>) So your final code should look something like:

<div class="input-dropdown-wrapper d-flex space-between vertical-center margin-right-12"
    ng-class="{'active': historyController.showFilterHistoryDurationDropdown === true}"
    ng-click="historyController.showFilterHistoryDurationDropdown ? historyController.showFilterHistoryDurationDropdown = false : historyController.showFilterHistoryDurationDropdown = true"
    when-clicked-off="historyController.showFilterHistoryDurationDropdown = false">
  <p>
      Show {{historyController.filter}} <br>
      showFilterHistoryDurationDropdown : {{historyController.showFilterHistoryDurationDropdown}}
  </p>
  <i class="fas fa-angle-down"></i>
  <ul class="input-dropdown"
      ng-if="historyController.showFilterHistoryDurationDropdown">
      <li ng-class="{'active': historyController.filter === 'All'}"
          ng-click="historyController.filter = 'All';
          historyController.showFilterHistoryDurationDropdown = false">
          Show All
      </li>
      <li ng-class="{'active': historyController.filter === 'In Progress'}"
          ng-click="historyController.filter = 'In Progress';
          historyController.showFilterHistoryDurationDropdown = false">
          Show In Progress
      </li>
      <li ng-class="{'active': historyController.filter === 'Completed'}"
          ng-click="historyController.filter = 'Completed';
          historyController.showFilterHistoryDurationDropdown = false">
          Show Completed
      </li>
  </ul>

Hope this helps.. :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.