Angular Modal ng-click不起作用

Angular Modal ng-click does not work

本文关键字:不起作用 ng-click Modal Angular      更新时间:2023-09-26

我在angular中做了一个模态,它弹出得很好,但是退出按钮没有触发关闭模态。如果要打开的按钮被重新单击,但在模态中添加一个新按钮不会触发该函数,则它会工作。顺便说一句,这里没有引导。

    <section  class="modal" ng-show="showMenu">
    <div ng-click="setActive(album)">
    <p class="exit" ng-click="modalFunc()"><i class="fa fa-times-circle fa-2x" aria-hidden="true"></i></p>
    <h1>{{albumMod.artist}} - {{albumMod.title}}</h1>
    <ul class="tracks">
      <span><img src={{albumMod.img}}></span>
      <li>Album: {{albumMod.album}}</li>
      <li>Price: $1.29</li>
    </ul>
    <form style="display: inline" action="/#cart" method="get">
      <button ng-click="setActive(album); cartFunc()" id="{{album.id}}"><a>Add</a></button>
  </form>
  </div>
</section>

     $scope.closeMenu=true;
 $scope.showMenu=false;
 $scope.showItems=false;
 $scope.modalFunc= function(){
   $scope.showMenu = !$scope.showMenu;
   console.log($scope.selected);
   $scope.showItems = !$scope.showItems;
   $scope.closeMenu=!$scope.closeMenu;
   // console.log($scope.selected.attr("id"));
 };

$scope。你用来隐藏弹出窗口的showMenu标志没有正确使用。当美元范围。调用modalFunc方法,然后将$scope的值取反。showMenu和assigned。赋值后,输入$scope。showMenu值将为true。现在你已经使用了ng-show="showMenu",这样你的弹出窗口就不会被隐藏了。

正确的代码是:

1. Set $scope.showMenu = true in the callback which called when popup is opened.
2. $scope.modalFunc= function(){
   $scope.showMenu = !$scope.showMenu;
...
}
3. Remove $scope.showMenu=false; since it is not needed.