官方文档的调用方式
import { Events } from 'ionic-angular';
constructor(public events: Events) {}
// first page (publish an event when a user is created)
function createUser(user) {
console.log('User created!')
events.publish('user:created', user, Date.now());
}
// second page (listen for the user created event)
events.subscribe('user:created', (user, time) => {
// user and time are the same arguments passed in `events.publish(user, time)`
console.log('Welcome', user, 'at', time);
});
Events 有三个方法 分别是:
this.events.publish () //注册Events事件
this.events.subscribe() //调用Eevents事件
this.events.unsubscribe() //注销Events事件q
网友评论