首次使用Ionic,在按钮点击时获取弹出警示框

3
我正在尝试理解Ionic框架的工作原理以及如何使用控制器。更具体地说,我正在尝试通过文档中的一些代码向滑动条示例添加一个显示警报/弹出窗口的按钮。但是,不幸的是没有成功。我不确定如何调试应用程序,因为Ionic服务器与模拟器不一致。有没有好的教程(不是官方页面)?最好的方法是什么?我进展太慢了。顺便说一下,我熟悉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');
        });
    };
};
});

修复了 感谢您的输入。我会尝试修复它。我意识到这不是ionic,而是angularjs,我现在找到了一本好书可以阅读。谢谢


请将您的标题更改为有意义且包含真实信息的内容。否则,您的问题将不会得到任何关注。 - dertkw
3
$scope.showAlert 从未被调用。 - merlin
1个回答

4

正如Merlin所说,当调用showPopup函数时不会运行showAlert()函数。以下是控制器应该呈现的样子:

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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接