Sharath Bangera
Sharath Bangera

Reputation: 114

Meteor: Importing a JS file isn't working

I have created a JS file inside the lib folder which has a JSON Object assigned to a variable and i am trying to use that variable in the Client folder, in of the template helper function but i get error while running saying the variable isn't defined.

How to solve this ? How to use this variable in both Client and Server ?

deviceMap.js -> inside lib folder

var deviceMap = {
    "123456": {
        "name": "ABC",
        "department": "dept1"
    }
}

Template.tmp1.helpers({
   console.log(deviceMap);
});

Thank you

Upvotes: 0

Views: 277

Answers (1)

David Weldon
David Weldon

Reputation: 64342

Prior to meteor 1.3, the only way to share variables between files is through the global namespace.

Replace:

var deviceMap =

with:

deviceMap =

and your variable will be global instead of file scoped. You may also want to consider namespacing your variable like: DeviceMaps.departments or something.

Upvotes: 3

Related Questions