2016-08-22 14 views
0

最近、onsen-uiを取り組んでいて、TabbarとNavigatorコンポーネント内でCarrousel var(var="carousel")を参照しようとしていました。Onsen-ui Carrousel var属性がTabbarと連携していません

コードは、タブを使用するまで機能します。私は次のエラーを取得:

Uncaught (in promise) TypeError: Cannot read property of undefined

を私は「pageinit」ソリューションを疲れましたが、機能していないようです。

ここではHTMLの下にあります。

<!doctype html> 
<html> 
<head> 
    <meta charset="utf-8"> 
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"> 
    <meta http-equiv="Content-Security-Policy" content="default-src * data:; style-src * 'unsafe-inline'; script-src * 'unsafe-inline' 'unsafe-eval'"> 
    <link rel="stylesheet" href="lib/onsen/css/onsenui.css"> 
    <link rel="stylesheet" href="lib/onsen/css/onsen-css-components.css"> 
    <link rel="stylesheet" href="css/style.css"> 
    <script src="lib/onsen/js/angular/angular.min.js"></script> 
    <script src="lib/onsen/js/onsenui.min.js"></script> 
    <script src="lib/onsen/js/angular-onsenui.min.js"></script> 
    <script src="js/app.js"></script> 
</head> 
<body ng-controller="AppCtrl"> 
    <ons-tabbar> 
     <ons-tab page="home.html" active="true"> 
     <ons-icon icon="ion-home"></ons-icon> 
     <span style="font-size: 14px">Home</span> 
     </ons-tab> 
    </ons-tabbar> 
    <ons-template id="home.html"> 
     <ons-navigator title="Navigator" var="myNavigator"> 
      <ons-page> 
       <ons-toolbar> 
       <div class="center">Carousel</div> 
       </ons-toolbar> 
       <ons-carousel ng-controller="carouselCtrl" swipeable overscrollable auto-scroll fullscreen var="carousel"> 
       <ons-carousel-item style="background-color: gray;" id="carouselWho"> 
        <div class="item-label">1</div> 
       </ons-carousel-item> 
       <ons-carousel-item style="background-color: #D38312;" id="carouselWhere"> 
        <div class="item-label">2</div> 
       </ons-carousel-item> 
       <ons-carousel-cover> 
        <div class="cover-label"> 
        <ons-icon icon="ion-ios-home" size="20px" fixed-width="true" ng-class="{'custom-icon': iconIndex == 'carouselWho'}"></ons-icon> 
        <ons-icon icon="ion-ios-location" size="20px" fixed-width="true" ng-class="{'custom-icon': iconIndex == 'carouselWhere'}"></ons-icon> 
       </div> 
       </ons-carousel-cover> 
       </ons-carousel> 
      </ons-page> 
     </ons-navigator> 
    </ons-template> 
</body> 
</html> 

そして

var module = ons.bootstrap('my-app', ['onsen']); 

module.controller('AppCtrl',['$scope', function($scope) { 

}]); 

module.controller('carouselCtrl',['$scope', function($scope) { 

    ons.ready(function() { 

     $scope.iconIndex = $scope.carousel._attrs.$$element[0].children[$scope.carousel.getActiveIndex()].id; 
     $scope.$apply(); 

     $scope.carousel.on('postchange', function (event) { 
      $scope.iconIndex = $scope.carousel._attrs.$$element[0].children[$scope.carousel.getActiveIndex()].id; 
      $scope.$apply() 
     }); 

    }); 

}]); 

あなたは問題がから来ている任意のアイデアを持っていますがapp.js?

お時間をありがとうございました。

答えて

0

あなたのHTMLにタブを追加し、それをcodepenに入れました。それは動作するようですか?エラーが発生したときに何が起きるかを指定できますか?

<html> 
<head> 
    <meta charset="utf-8"> 
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"> 
    <meta http-equiv="Content-Security-Policy" content="default-src * data:; style-src * 'unsafe-inline'; script-src * 'unsafe-inline' 'unsafe-eval'"> 
</head> 
<body ng-controller="AppCtrl"> 
    <ons-tabbar> 
     <ons-tab page="home.html" active="true"> 
     <ons-icon icon="ion-home"></ons-icon> 
     <span style="font-size: 14px">Home</span> 
     </ons-tab> 
     <ons-tab page="home2.html" active="true"> 
     <ons-icon icon="ion-home"></ons-icon> 
     <span style="font-size: 14px">Home</span> 
     </ons-tab> 
    </ons-tabbar> 
    <ons-template id="home.html"> 
     <ons-navigator title="Navigator" var="myNavigator"> 
      <ons-page> 
       <ons-toolbar> 
       <div class="center">Carousel</div> 
       </ons-toolbar> 
       <ons-carousel ng-controller="carouselCtrl" swipeable overscrollable auto-scroll fullscreen var="carousel"> 
       <ons-carousel-item style="background-color: gray;" id="carouselWho"> 
        <div class="item-label">1</div> 
       </ons-carousel-item> 
       <ons-carousel-item style="background-color: #D38312;" id="carouselWhere"> 
        <div class="item-label">2</div> 
       </ons-carousel-item> 
       <ons-carousel-cover> 
        <div class="cover-label"> 
        <ons-icon icon="ion-ios-home" size="20px" fixed-width="true" ng-class="{'custom-icon': iconIndex == 'carouselWho'}"></ons-icon> 
        <ons-icon icon="ion-ios-location" size="20px" fixed-width="true" ng-class="{'custom-icon': iconIndex == 'carouselWhere'}"></ons-icon> 
        </div> 
       </ons-carousel-cover> 
       </ons-carousel> 
      </ons-page> 
     </ons-navigator> 
    </ons-template> 
    <ons-template id="home2.html"> 
     <ons-navigator title="Navigator" var="myNavigator"> 
      <ons-page> 
       <ons-toolbar> 
       <div class="center">Carousel</div> 
       </ons-toolbar> 
       <ons-carousel ng-controller="carouselCtrl" swipeable overscrollable auto-scroll fullscreen var="carousel"> 
       <ons-carousel-item style="background-color: gray;" id="carouselWho"> 
        <div class="item-label">3</div> 
       </ons-carousel-item> 
       <ons-carousel-item style="background-color: #D38312;" id="carouselWhere"> 
        <div class="item-label">4</div> 
       </ons-carousel-item> 
       <ons-carousel-cover> 
        <div class="cover-label"> 
        <ons-icon icon="ion-ios-home" size="20px" fixed-width="true" ng-class="{'custom-icon': iconIndex == 'carouselWho'}"></ons-icon> 
        <ons-icon icon="ion-ios-location" size="20px" fixed-width="true" ng-class="{'custom-icon': iconIndex == 'carouselWhere'}"></ons-icon> 
        </div> 
       </ons-carousel-cover> 
       </ons-carousel> 
      </ons-page> 
     </ons-navigator> 
    </ons-template> 
</body> 
</html> 

https://codepen.io/grailly/pen/wWLavb?&editors=101

+0

こんにちは、答えるために感謝します。私は明確ではなかったと信じて、申し訳ありません。私の問題はタブ自体に関連するものではなく、タブ内で初期化時に 'カルーセル'変数を読み込むことで問題になります。 –

関連する問題