ionic 主動觸發(fā)下拉刷新

ionic3?主動觸發(fā)下拉刷新指令

用法

? ?頁面加載的時候觸發(fā)

添加在ion-refresher

? ?每次進入頁面視圖的時候觸發(fā)


指令代碼

import { Directive, OnInit, Injector, Input } from '@angular/core';

import { Refresher, Content, ViewController } from 'ionic-angular';

@Directive({

? selector: '[beginRefresh]'

})

export class BeginRefreshDirective implements OnInit {

? @Input('beginRefresh')? private _beginRefresh = false;

? constructor(

? ? private injector: Injector,

? ? private viewCtrl: ViewController

? ) {

? }

? ngOnInit() {

? ? if (!this._beginRefresh) {

? ? ? this.beginRefresh();

? ? } else {

? ? ? this.viewCtrl.didEnter.subscribe(() => {

? ? ? ? this.beginRefresh();

? ? ? });

? ? }

? }

? private async beginRefresh() {

? ? const top = await this.getContentTop();

? ? const refresher = this.injector.get(Refresher);

? ? refresher._top = `${top}px`;

? ? refresher.state = 'refreshing';

? ? refresher._beginRefresh();

? }

? private getContentTop(): Promise<number> {

? ? const content = this.injector.get(Content);

? ? return new Promise((resolve, reject) => {

? ? ? const timer = setInterval(() => {

? ? ? ? if (content.contentTop) {

? ? ? ? ? resolve(content.contentTop);

? ? ? ? ? clearInterval(timer);

? ? ? ? }

? ? ? }, 0);

? ? });

? }

}

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

  • core package 概要:Core是所有其他包的基礎包.它提供了大部分功能包括metadata,templa...
    LOVE小狼閱讀 2,881評論 0 3
  • 1.一些開放性題目 1.自我介紹:除了基本個人信息以外,面試官更想聽的是你與眾不同的地方和你的優(yōu)勢。 2.項目介紹...
    55lover閱讀 715評論 0 6
  • 我家寶寶馬上兩個月了,還沒有聚肚,滿月之后便便次數(shù)漸漸減少,由一天八九次逐漸減少到一兩次。最近天氣時暖時冷,寶寶有...
    王飛俠閱讀 38,025評論 6 5
  • 迭代器模式: 提供一種方法順序訪問一個聚合對象中的各個元素,而又不暴露其內部的表示。 比如說,現(xiàn)在我們有兩個聚合對...
    ghwaphon閱讀 1,548評論 0 5
  • 寫歐體,需要知道用筆、筆法和結體! (一) 用筆 歐字法度森嚴,源自魏碑,字形偏長,這些顯著的特點...
    墨緣革離閱讀 2,346評論 4 8

友情鏈接更多精彩內容