使用离子的第一步,在按钮点击/点击时获得弹出警报 [英] First steps with ionic to get popup alert on button tap / click

查看:94
本文介绍了使用离子的第一步,在按钮点击/点击时获得弹出警报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图了解离子框架如何工作以及如何使用控制器的概念。
更具体地说,我正在尝试添加一个按钮,该按钮会向幻灯片示例显示警报/弹出窗口,其中包含文档中的一些代码。
不幸的是没有
的成功。我不确定如何调试应用程序,因为离子服务器与模拟器不一致。
那里有一个很好的教程(不是官方页面)吗?挖掘它的最佳方法是什么?为了我的口味,我正在变慢。顺便说一下,我熟悉ios编码,我有点想念舒适的ios环境......

I am trying to understand the concept how ionic framework works and how to use the controllers. More specifically, I am trying to add a button that would display a alert / popup to the slidebar example with some code from the documentation. Unfortunately no success. I am not sure how to debug the app because the ionic server is not consistent with the simulator. Is there a good tutorial (not the official page) out there? What is the best way to dig into it? I am moving to slow for my taste. I am familiar with ios coding by the way, and I sort of miss the comfortable ios environment...

这是我为按钮提醒编写的代码点击:$ b其中一个html文件中的$ b

Here's the code I wrote for the button alert click: in one of the html files

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

controller.js中的

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

固定
感谢您的输入。我会尝试解决它。我意识到这不是离子,而是我必须阅读的棱镜,为此我现在找到了一本好书。谢谢

Fixed Thanks for the input. I'll try to fix it. I realized that it's not ionic but angularjs that I have to read upon, for which I now found a good book.Thanks

推荐答案

正如merlin所说,当调用showPopup时,showAlert()不会运行。这是控制器应该是什么样子

As merlin said the showAlert() is not run when showPopup is called. Here is what the controller should look like

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

这篇关于使用离子的第一步,在按钮点击/点击时获得弹出警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆