按照这个http://www.angular-meteor.com/tutorials/socially/angular2/meteor-methods
有:
Meteor.methods({
invite: function(partyId: string, userId: string) {
check(partyId, String);
check(userId, String);
let party = Parties.findOne(partyId);
if (!party)
throw new Meteor.Error('404', 'No such party!');
if (party.public)
throw new Meteor.Error('400', 'That party is public. No need to invite people.');
if (party.owner !== this.userId)
throw new Meteor.Error('403', 'No permissions!');
if (userId !== party.owner && (party.invited || []).indexOf(userId) == -1) {
Parties.update(partyId, { $addToSet: { invited: userId } });
let from = getContactEmail(Meteor.users.findOne(this.userId));
let to = getContactEmail(Meteor.users.findOne(userId));
if (Meteor.isServer && to) {
Email.send({
from: 'noreply@socially.com',
to: to,
replyTo: from || undefined,
subject: 'PARTY: ' + party.name,
text: `Hi, I just invited you to ${party.name} on Socially.
\n\nCome check it out: ${Meteor.absoluteUrl()}\n`
});
}
}
}
})
然后在 Party-Detail.ts 我们有
invite(user:Meteor.User) {
this.call('invite', this.party._id, user._id, (error) => {
if (error) {
alert(`Failed to invite due to ${error}`);
return;
}
alert('User successfully invited.');
});
}
当用户点击 Invite 时代码是如何执行的?
同时在客户端和服务器端?