Preety Sapra
Preety Sapra

Reputation: 615

How can I call the api on onclick in POPUP using IONIC and AngularJs?

I have popup demo which is working simply, but now have call the api on onclick of the button in popup.

This code taking two button with default name and I want to change the name of button.

$scope.OnAppointment = function() {
               var confirmPopup = $ionicPopup.confirm({
               title: 'My Appointment',
            });
            confirmPopup.then(function(res) {
           if(res) {
             console.log('You are sure');
           } else {
              var alertPopup = $ionicPopup.alert({
               title: 'Cancle Appointment',
               template: 'Are you sure you want to cancle the appointment?'
             });
             alertPopup.then(function(res) {
               console.log('Sucessfully Cancel');
             });
           }

Please tell me how can call the api on onclick in popup button and change the button name....

Upvotes: 0

Views: 632

Answers (2)

Jonathan Rowny
Jonathan Rowny

Reputation: 7588

To call an API you need a service. The built in $http service works fine for a simple call. You can inject it like anything else. $http.get('/api/somewhere').then( etc.. or $http.post('/api/somewhere') would simply go where your console.log is currently. See the $http documentation for more info.

As you get more advanced you'll want to abstract these calls into your own service which you can define with app.service('myService', function(){ //methods in your service });

Upvotes: 1

GeekOnGadgets
GeekOnGadgets

Reputation: 959

You have to create the Services-here you make the call to API , then in your controller you call that services and at last from view you call the controller. I would suggest you to start looking at

1) Services - 2) Controller and $Scope

Upvotes: 0

Related Questions