gpt4 book ai didi

javascript - Ionic/Angular 混合应用程序,让摇动事件起作用的问题

转载 作者:行者123 更新时间:2023-11-30 15:53:49 24 4
gpt4 key购买 nike

这适用于 Ionic/Angular 混合应用。我正在尝试使用 cordova-plugin-shake 触发 摇动事件 .它应该重新加载随机图像。到目前为止,加载时会显示随机图像,但在模拟器中测试 shake 事件 时它不起作用。

我收到错误 ReferenceError: shake is not defined 但是文档说 你不需要引用任何 JavaScript,Cordova 插件架构会在你的根中添加一个 shake 对象构建时自动。 我在这里缺少什么?我怎样才能让它工作?我正在使用 cordova 6.3.0 版。

这是 app.js

angular.module('TarotApp', ['ionic','ngAnimate'])

.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
if(window.cordova && window.cordova.plugins.Keyboard) {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);

// Don't remove this line unless you know what you are doing. It stops the viewport
// from snapping when text inputs are focused. Ionic handles this internally for
// a much nicer keyboard experience.
cordova.plugins.Keyboard.disableScroll(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
shake.startWatch(onShake, 40);
});
})

angular.module('TarotApp')
.controller('TarotCtrl', function ($scope) {

$scope.tarotImg = ['1', '2', '3', '4', '5', '6'];

$scope.randTarotImg = $scope.tarotImg[Math.floor(Math.random() * $scope.tarotImg.length)];


});

var onShake = function () {
$scope.randTarotImg = $scope.tarotImg[Math.floor(Math.random() * $scope.tarotImg.length)];
};

这是index.html

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title></title>

<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">

<!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
<link href="css/ionic.app.css" rel="stylesheet">
-->

<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>
<script src="lib/angular-animate/angular-animate.min.js"></script>

<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>

<!-- your app's js -->
<script src="js/app.js"></script>
</head>
<body ng-app="TarotApp">

<ion-pane>

<!-- <ion-header-bar class="bar-stable">

</ion-header-bar>-->

<ion-content ng-controller="TarotCtrl">


<img ng-src="img/{{randTarotImg}}.jpg" class="tarot"/>


</ion-content>

</ion-pane>



</body>
</html>

最佳答案

仅当您构建并部署到真实手机时,才会添加 shake 对象。如果您在浏览器中进行测试,则不会。添加这个可以避免测试时出错

if(window.shake) shake.startWatch(onShake,40);

关于javascript - Ionic/Angular 混合应用程序,让摇动事件起作用的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38907147/

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