click event ng-click not working

爷,独闯天下 提交于 2019-12-24 12:53:11

问题


History and Home page are work fine but 'ng-click="toggleMenu()"' are not working so please help me click event ng-click="toggleMenu()"is not working..

can anyone help me to solve it?

My code is,

<ion-tab title="History" icon-off="ion-document" icon-on="ion-document-text" href="#/tab/history">
<ion-nav-view name="tab-history"></ion-nav-view>
</ion-tab> 
<a class="button"  ng-click="toggleMenu()">More</a>

.controller('MoreCtrl', function($scope,$ionicSideMenuDelegate) {

$scope.toggleMenu = function()
{
    alert('test toggle');
    $ionicSideMenuDelegate.toggleRight();
};

})

回答1:


I think controller are not required here . can you try this way.

 <ion-tab title="More" icon-off="ion-ios-more-outline" icon-on="ion-ios-more" ng-click="toggleMenu()"> 
                             </ion-tab> 
                          </ion-tabs>
        .run(function($ionicPlatform,$state,$rootScope,$ionicActionSheet,$ionicSideMenuDelegate) {

            $rootScope.toggleMenu = function() {

                alert('test toggle');
                $ionicSideMenuDelegate.toggleRight();
            }
        })

check this question please Ionic framework ion tabs not firing event

more information this link for demo
http://codepen.io/cfjedimaster/pen/iplCx




回答2:


Please add your full html code. Have you correctly attached MoreCtrl to the DOM? Is your DOM in line with Ionic guidelines for $ionicSideMenuDelegate? I don't see the <ion-side-menus> tag for example, like below:

<body ng-controller="MoreCtrl">
  <ion-side-menus>
    <ion-side-menu-content>
      Content!
      <button ng-click="toggleRightSideMenu()">
        Toggle Right Side Menu
      </button>
    </ion-side-menu-content>
  </ion-side-menus>
</body>


来源:https://stackoverflow.com/questions/35426093/click-event-ng-click-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!