使用" var =!var"

时间:2015-08-04 15:20:48

标签: angularjs boolean angularjs-ng-click

<accordion class="nested-accordion">
    <accordion-group ng-repeat="item in menu" is-open="item.opened" ng-if="item.children == true && item.grandchild == true">
          <accordion-heading id="inner-accordion">

         ---- PROBLEM HERE ----
            <div ng-click="item.opened = !item.opened" class="toggle-caret">
                  <span class="glyphicon glyphicon-play" ng-class="{true: 'caret-open', false:'caret-closed'}[item.opened]"></span>
              </div>


              <button class="btn-link filter-option" ng-class="{true:'option-checked', false:''}[item.checked]" ng-click="test(item, $event); $event.stopPropagation()">{{item.name}}</button>
          </accordion-heading>
                    <div>
                 <!--  some stuff here -->
                    </div>
                  </accordion-group>
                </accordion>

我在上面的代码中单独列出的一行有问题。 ng-click不会将 item.opened true 切换为 false 。但是,如果我更改语法:

ng-click="item.opened = !item.opened"

为:

ng-click="item.opened != item.opened"

手风琴按预期工作。这不是我想要的。 此外,这是手风琴中遇到此问题的唯一部分。谁能解释为什么这给我带来了困难?

0 个答案:

没有答案