Meteor methods are a way to perform more complex logic. Meteor methods are responsible for checking permissions. This is the better and more secure way than call things like insert, update or remove on a collection directly from your client. In this post, I want to show you quickly and simple how you can return something from a method and use it in our client code. In the same you will also see how you can catch an error if there is one. Meteor itself uses method calls with callbacks and Angular-Meteor enhances Meteor methods with promises, so I will show you both ways of handling it.

First, let’s create our Meteor method for our testing purpose

So, this is our test method. It will return a string when param is not null or undefined, otherwise throw a new Meteor.Error.

Use it with Angular-Meteor and promises

With Angular-Meteor, we have a service called $meteor, which wraps Meteor calls in promises. So, lets consume our Meteor method in our Angular client

So, if the param here is not set or undefined, we will land in the error, otherwise we get the string from the method.

Use it with Meteor and callbacks

With Angular-Meteor, we have a service called $meteor, which wraps Meteor calls in promises. So, lets consume our Meteor method in our Angular client

Same here, if the param here is not set or undefined, we will land in the error, otherwise we get the string from the method.

 

Return a value from a Meteor method and catch return value or error on Angular client
Tagged on:     

Leave a Reply

Follow

Get every new post on this blog delivered to your Inbox.

Join other followers:

Welcome Damir Kusar

Log in

Lost your password?
%d bloggers like this: