2014-06-19 49 views
3

我想了解離子框架如何工作以及如何使用控制器的概念。 更具體地說,我試圖添加一個按鈕,該按鈕將顯示一個警告/彈出式窗口示例與文檔中的一些代碼。 不幸的是沒有 成功。我不確定如何調試應用程序,因爲離子服務器與模擬器不一致。 那裏有一個很好的教程(不是官方網頁)嗎?挖掘它的最佳方法是什麼?我正在爲我的口味慢下來。我熟悉IOS的方式編碼,和我有點想念舒適的IOS環境...用離子的第一步按鈕點擊/點擊獲得彈出警報

這是我寫的按鈕提示單擊代碼: 在HTML文件中的一個

<button ng-click="showPopup()" class="button icon ion-edit"></button> 

在controllers.js

.controller('PlaylistsCtrl',function($scope, $ionicPopup, $timeout) { 

// Triggered on a button click, or some other target 
$scope.showPopup = function() { 
    $scope.data = {} 

    // An alert dialog 
    $scope.showAlert = function() { 
     var alertPopup = $ionicPopup.alert({ 
      title: 'Don\'t eat that!', 
      template: 'It might taste good' 
     }); 
     alertPopup.then(function(res) { 
      console.log('Thank you for not eating my delicious ice cream cone'); 
     }); 
    }; 
}; 
}); 

固定 感謝您的輸入。我會盡力修復它。我意識到,它不是離子的,但我必須閱讀,爲此,我現在找到了一本好書。謝謝

+0

請改變你的標題一些有意義的事情的真實信息。否則你的問題將不會得到任何關注。 – timbooo

+3

'$ scope.showAlert'永遠不會被調用。 – merlin

回答

3

由於merlin說showAlert()不會在showPopup被調用時運行。這裏是控制器應該是什麼樣子

angular.module('ionicApp', ['ionic']) 

.controller('PlaylistsCtrl', function($scope, $ionicPopup, $timeout) { 
    $scope.data = {} 

    // Triggered on a button click, or some other target 
    $scope.showPopup = function() { 
    var alertPopup = $ionicPopup.alert({ 
     title: 'Dont eat that!', 
     template: 'It might taste good' 
    }); 
    alertPopup.then(function(res) { 
     console.log('Thank you for not eating my delicious ice cream cone'); 
    }); 
    }; 
}); 

工作例如:

http://codepen.io/hannuraina/pen/qIbsE?editors=101