monacaでonsen uiを使ってスマートフォンアプリを作っています。
###やりたいこと
ons-carouselで画面が切り替わったときのイベントを発生させたいと思っています。
###問題点
ons-tabbarでページを切り替えたあと、
また元のページに戻ってカルーセルを移動させるとイベントが発生しなくなります。
###現状
初期状態ではイベントは発生します。
また、タブを切り替えて元のページに戻ったあと、index.htmlのons.readyのfunctionの中身自体は実行されました。
どこに原因があるのかすらわかっていないので、ソースコードなど指摘箇所を
教えていただけると幸いです。
よろしくお願いします。
index.html
html
1<!DOCTYPE HTML> 2<html> 3<head> 4 <meta charset="utf-8"> 5 <link rel="stylesheet" href="components/loader.css"> 6 <link rel="stylesheet" href="css/style.css"> 7 <script type="text/javascript" charset="utf-8" src="components/loader.js"></script> 8 <script> 9 ons.bootstrap() 10 .controller('MyCtrl', ['$scope', function($scope){ 11 ons.ready(function() { 12 //カルーセル移動時 13 carousel.on('postchange', function() { 14 window.alert('OK'); 15 }); 16 }); 17 }]); 18 </script> 19</head> 20<body> 21 <ons-tabbar var="tabbar"> 22 <ons-tab page="page1.html" active="true"><ons-icon icon="comment"></ons-icon></ons-tab> 23 <ons-tab page="page2.html"><ons-icon icon="user"></ons-icon></ons-tab> 24 </ons-tabbar> 25</body> 26</html>
page1.html
html
1<ons-page ng-controller="MyCtrl"> 2 <ons-toolbar> 3 <div class="center">Page 1</div> 4 </ons-toolbar> 5 <ons-carousel swipeable overscrollable auto-scroll fullscreen var="carousel"> 6 <ons-carousel-item> 7 <div style="text-align: center"> 8 <h1>Page 1</h1> 9 <p>test 1</p> 10 </div> 11 </ons-carousel-item> 12 <ons-carousel-item> 13 <div style="text-align: center"> 14 <h1>Page Carousel</h1> 15 <p>test carousel</p> 16 </div> 17 </ons-carousel-item> 18 </ons-carousel> 19</ons-page>
page2.html
html
1<ons-page> 2 <ons-toolbar> 3 <div class="center">Page 2</div> 4 </ons-toolbar> 5 <div style="text-align: center"> 6 <h1>Page 2</h1> 7 </div> 8</ons-page>
あなたの回答
tips
プレビュー