2018-02-03

作者: 赤洱 | 来源:发表于2018-02-03 11:30 被阅读18次

    Ionic3 发布/订阅
    https://ionicframework.com/docs/api/util/Events/

    发布:
    import { Events } from 'ionic-angular'; //导入
    ...
    export class EventsPage {
    user = '来自Events的数据'

    constructor(public events: Events) {}

    publishEvents(user) {
    console.log('User created!')
    this.events.publish('user:created',this.user, Date.now());
    console.log(this.user)
    }
    }
    订阅
    import { Component} from '@angular/core';
    import { Events } from 'ionic-angular';

    @Component({
    selector: 'page-home',
    templateUrl: 'home.html'
    })
    export class HomePage {
    myEvent;
    constructor(public events: Events) {
    events.subscribe('user:created', (user, time) => {
    HomePage.prototype.myEvent = user;
    });
    }
    }

    转自:http://blog.csdn.net/xundh/article/details/79048843

    相关文章

      网友评论

        本文标题:2018-02-03

        本文链接:https://www.haomeiwen.com/subject/vhcuzxtx.html