我想将项目滚动到屏幕顶部。当按下该项目时。我正在使用以下代码。
<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 :(得分:0)
问题是$ timeout需要一个函数作为第一个参数,而你执行一个函数。您必须从scrollTop()
方法中删除括号:
$timeout($ionicScrollDelegate.$getByHandle(index).scrollTop,3000);
现在该函数将在3000
ms后执行,并在正确的上下文中(可以找到处理程序)