2

I added a ion-nav-button exactly as documented (direct descendant of the ion-view) and added an ng-click event that isn't firing.

Any idea why?

I attached a plunkr of the issue.

http://plnkr.co/edit/cZ9wDlhJJzebBr1WR3rT?p=preview

Thanks! Uri

<ion-view title="Dashboard">
  <ion-nav-buttons side="right">
    <button class="button" ng-click="alert('signup btn clicked');">
      Signup
    </button>
  </ion-nav-buttons>
  <ion-content class="has-header padding">
    <h1>Ionic scroll</h1>
    <p>On iphone tapping slightly above or below text doesn't open keyboard.</p>
    <input type="text" name="name" style="border: 1px solid grey;">
  </ion-content>
</ion-view>
Uri Klar
  • 3,800
  • 3
  • 37
  • 75

2 Answers2

3

That's because in the DashController there is no function alert(...); The ng-click="alert('xx') is translated in to $scope.alert('xx');

So if you create in the DashController:

$scope.alert = function(text) {
  alert(text);
}

it will work.

Toxus
  • 655
  • 5
  • 11
  • If one is wondering why AngularJS does not throw an exception, I found this useful: http://stackoverflow.com/questions/21297108/angularjs-ng-click-silently-eats-errors – Justin Fisher Jun 16 '15 at 13:47
2

This answer is for those who are wondering why ng-click is not working even after writing the function in the Controller. Please check whether you have mentioned the controller as shown below:

$stateProvider
  .state('dashboard', {
    url: '/',
    templateUrl: 'dashboard.html',
    controller: 'DashController'
  })
Selva
  • 338
  • 2
  • 12