How to Implement the pull-down refresh and pull-up loading functions for Ionic?

Source: Internet
Author: User

How to Implement the pull-down refresh and pull-up loading functions for Ionic?

IONIC is currently the most promising HTML5 mobile app development framework. SASS is used to build applications. It provides many UI components to help developers develop powerful applications. It uses JavaScript MVVM framework and AngularJS to enhance applications. Provides two-way data binding, which can be used by Web and mobile developers. Ionic is a development framework that focuses on WEB development technology and creates native applications similar to mobile phone platforms based on html5. The Ionic framework is designed to develop mobile apps from the web perspective. The PhoneGap-based compilation platform can be used to compile apps on various platforms.

This article describes how to implement the pull-down refresh and pull-up loading functions in Ioinc. This feature is often used in project development. If you are interested, check it out.

HTML section

<Ion-view-title = "Message notification"> <ion-content class = "padding"> <! -- <Ion-refresher> Pull-down refresh command --> <ion-refresher pulling-text = "Pull to refresh" on-refresh = "vm. doRefresh () "> </ion-refresher> <div class =" list card "ng-repeat =" message in vm. messages "> <div class =" item-divider item-icon-right ">{{ message. title }}< I class = "icon" ng-click = "vm. show (message) "ng-class =" message. static? 'Ion-arrow-down-B ': 'ion-arrow-right-B '"> </I> </div> <div class =" item-body "> <div >{{ message. static? Message. content: message. content. substr (,) }}</div> <! -- Ion-infinite-scroll: when the value of the data instruction distance % nf-if is false by default, on-infinite --> <ion-infinite-scroll ng-if = "! Vm. moredata "on-infinite =" vm. loadMore () "distance =" % "> </ion-infinite-scroll> </ion-content> </ion-view>

JS Section

• Before the function execution that is triggered by the on-refresh drop-down, you must broadcast the end of the event $ scope. $ broadcast ('scroll. refreshcomplete ');

• Functions triggered by pulling on-infinite also need to broadcast events to end $ scope. $ broadcast ('scroll. infinitescrollcomplete ');

angular.module(‘starter.controllers‘, []).controller(‘InfoCtrl‘, function($rootScope, $timeout, $interval, $scope, $http, services) {var vm = $scope.vm = {moredata: false,messages: [],pagination: {perPage: ,currentPage: },init: function () {services.getMessages({perPage: vm.pagination.perPage, page: vm.pagination.currentPage}, function (data) {vm.messages = data;})},show: function (message) {if (message.static) {message.static = false;} else {message.static = true;}},doRefresh: function () {$timeout(function () {$scope.$broadcast(‘scroll.refreshComplete‘);}, );},loadMore: function () {vm.pagination.currentPage += ;services.getMessages({perPage: vm.pagination.perPage, page: vm.pagination.currentPage}, function (data) {vm.messages = vm.messages.concat(data);if (data.length == ) {vm.moredata = true;};$scope.$broadcast(‘scroll.infiniteScrollComplete‘);})} }vm.init();})

Here, messages is the data displayed by view, pagination is the parameter used for page loading and display, and service is the $ http service Encapsulated by me, the show method is used to display the view information (you do not need to pay attention to this )!

This article describes how to implement pull-down refresh and pull-up loading of Ionic. I hope it will be helpful to you, if you want to learn more, please stay tuned to the help House website!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.