Lemon Lemon - 7 months ago 21
Javascript Question

Passing data from controller to another controller

I am working on sails JS application.

Is there anyway to pass a data from another controller using sails JS?

// controller 1
exports.module{
passing data to controller 2
}

// controller2

exports.module{
get data from controller 1
}


or better, is there anyway to create a global variable which can be accessed by any controller in sails js? just like $_SESSION['sessionname'] in php?

Answer

You can use a Service, it enables you to access data everywhere in your code.

EDIT

You can also use the global variable sails:

sails.myObject = {}