gpt4 book ai didi

javascript - 使用 ionic 的第一步是在按钮点击/单击时获得弹出警报

转载 作者:行者123 更新时间:2023-11-29 10:14:57 25 4
gpt4 key购买 nike

我想了解 ionic 框架如何工作以及如何使用 Controller 的概念。更具体地说,我正在尝试添加一个按钮,该按钮将使用文档中的一些代码向滑动条示例显示警报/弹出窗口。很不幸的是,不行成功。我不确定如何调试应用程序,因为 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,为此我找到了一本好书。谢谢

最佳答案

正如 merlin 所说,调用 showPopup 时不会运行 showAlert()。这是 Controller 的样子

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

关于javascript - 使用 ionic 的第一步是在按钮点击/单击时获得弹出警报,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24299891/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com