2017-01-30 52 views
1

我想將項目滾動到屏幕頂部。當按下該項目時。我正在使用以下代碼。

<ion-list id="iphoneTutorials-list2" ng-repeat="(f,chapter) in iphoneVideos"> 
     <ion-item style="border-left: none;border-right: none;border-top: none;" class="item-text-wrap" ng-click="toggledisplay($index)" delegate-handle="$index"><i class="icon ion-ios-arrow-right" ng-if="!trigger[$index]"></i> 
    <i class="icon ion-ios-arrow-down" ng-if="trigger[$index]"></i> {{chapter.chapter_name}}</ion-item> 
     <ion-list ng-show="trigger[$index]"> 
     <ion-item class="item-text-wrap" ng-click="openVideo(video.video_id,video.video_name,f,$index,video.Description)" style="margin-left: 10%;border-left: none;border-right: none;" ng-repeat="video in chapter.chapter_content">{{video.video_name}}</ion-item> 
     </ion-list> 

和控制器我使用這個:

$rootScope.toggledisplay = function(index){ 
    $timeout($ionicScrollDelegate.$getByHandle(index).scrollTop(),3000); 
    if($rootScope.trigger[index]){ 
     $rootScope.trigger[index] = false; 

    } 
    else{ 
     $rootScope.trigger[index] = true; 
    } 
} 

消息我收到的控制檯:

ionic.bundle.js:26799 Delegate for handle "7" could not find a corresponding element with delegate-handle="7"! scrollTop() was not called! 
Possible cause: If you are calling scrollTop() immediately, and your element with delegate-handle="7" is a child of your controller, then your element may not be compiled yet. Put a $timeout around your call to scrollTop() and try again. 

任何可以幫助我與我的問題?

+0

這是離子的V1正確執行呢? –

回答

0

問題是$超時需要一個函數作爲第一個參數,而您是而不是執行函數。你必須從scrollTop()方法去掉括號:

$timeout($ionicScrollDelegate.$getByHandle(index).scrollTop,3000); 

現在的功能將在3000毫秒後在正確的上下文(其中處理器可以找到)