angularjs - Ionic & Angular JS - Close custom popup -


my question simple : want, when user click in button inside template, pop close. i've use :

my controller js :

  $scope.showalert = function() {    var alertpopup = $ionicpopup.alert({      templateurl: 'templates/popup.html'    });    alertpopup.then(function(res) {      console.log('thank not eating delicious ice cream cone');    });   };  var alertpopup;   $scope.sendorder = function() {   alertpopup.close(); }; 

with in button in template html :

<a class="button button-full " style="font-weight: bolder;" id="bwlogin" ng-click="sendorder()">fermer </a> 

but i've error :

>typeerror: cannot read property 'close' of undefined >>    @ scope.$scope.sendorder (controller.js:224) >>    @ $parsefunctioncall (ionic.bundle.js:21037) >>    @ ionic.bundle.js:53344 >>    @ scope.$get.scope.$eval (ionic.bundle.js:23093) >>    @ scope.$get.scope.$apply (ionic.bundle.js:23192) >>    @ htmlanchorelement.<anonymous> (ionic.bundle.js:53343) >>    @ htmlanchorelement.eventhandler (ionic.bundle.js:11706) >>    @ triggermouseevent (ionic.bundle.js:2863) >>    @ tapclick (ionic.bundle.js:2852) >>    @ htmldocument.tapmouseup (ionic.bundle.js:2925)(anonymous function) @ >>ionic.bundle.js:20299$get @ ionic.bundle.js:17249$get.scope.$apply @ >>ionic.bundle.js:23194(anonymous function) @ ionic.bundle.js:53343eventhandler @ >>ionic.bundle.js:11706triggermouseevent @ ionic.bundle.js:2863tapclick @ >>ionic.bundle.js:2852tapmouseup @ ionic.bundle.js:2925 

anyone can me ? time !

in code first alertpopup variable out of scope of sendorder function. when sendorder called. function using undefined value of

var alertpopup; 

this should work:

var alertpopup;   $scope.showalert = function() {        alertpopup = $ionicpopup.alert({          templateurl: 'templates/popup.html'        });        alertpopup.then(function(res) {          console.log('thank not eating delicious ice cream cone');        });       };       $scope.sendorder = function() {       alertpopup.close();     }; 

by example: http://jsbin.com/xuvefatoha/edit?html,js,console,output


Comments