Ng-click inside Modal is not working properly

I’m experiencing a weird behaviour with the ng-click directive inside . As you can see on the CodePen, the closeModal() function is not being called. If I switch for modal.hide() it does works, but if I switch for a console.log() or alert(), it also doesn’t work. Why? How can I resolve it?


That is definitely weird.

I managed to get to work using the close method directly in the ng-click.

<button ng-click="modal.hide()">Fechar Modal</button>

Just a side note, you are using controllerAs syntax in the ng-controller but aren’t using it then anywhere else.

<body ng-controller="ExampleCtrl as example">

You can use the controllerAs syntax with Ionic, but that means you’ll need to replace $scope with this and use example.openModal()

Still not sure why you can’t use the modal method within your function but!

1 Like

This is the problem

$ionicModal.fromTemplateUrl('my-modal.html', function(){
  scope: $scope
  $scope.modal = modal;

You are giving as options a function instead of a object. See


Working perfectly now. Thanks!