2014-06-19 50 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