2014-09-26 80 views
0

我有彈出演示工作簡單,但現在已經調用彈出窗口中按鈕的onclick上的api。如何使用IONIC和AngularJs在POPUP中的onclick上調用api?

此代碼採用兩個按鈕與默認名稱,我想更改按鈕的名稱。

$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'); 
      }); 
      } 

請告訴我如何能彈出式按鈕調用API上的onclick並更改按鈕的名稱....

回答

0

你要在這裏服務創建您撥打電話到API,然後在你的控制器你打電話給那個服務,最後從你看來你打電話給控制器。我建議你開始尋找

1)服務 - 2)控制器和$範圍

1

要叫你需要服務的API。內置的$ http服務適用於簡單的調用。你可以像其他任何東西一樣注入它。 $http.get('/api/somewhere').then(etc..$http.post('/api/somewhere')只會去你的console.log目前的位置。有關更多信息,請參閱$http documentation

你得到更先進的你要抽象這些調用到自己的服務,您可以用app.service('myService', function(){ //methods in your service });

定義