I want to have a global variable that is accessible to modify in any view in my application. I am wondering what this the best way to do so when using hot towel. Currently, I am declareing this variable in my shell.js and referencing this in subsequent views.
My shell.js returns the global variable. My other views have the shell defined at the top like define(['viewmodels/shell'], function(shell){}
and I access the shell variable like shell.variablename
. I am wondering if this is the best way of handling variables that need to be accessed by more than one view.
Asked
Active
Viewed 455 times
0

jpo
- 3,959
- 20
- 59
- 102
-
Using $rootScope is generally considered good practice. [Here is link to similar question with answer][1] [1]: http://stackoverflow.com/questions/11938380/global-variables-in-angularjs – Jacob Rutherford Oct 31 '14 at 16:33
1 Answers
2
It can be done in many ways , either u create a config.js or any file or u can include the following code inside 'vm' object.
// config.js
define(function () {
var variableName= 'BlahBlah';
return {
debugEnabled: ko.observable(true),
variableName :variableName
};
});
// include this config.js in any javascript file
define(['folderName/config'],
function (config) {
var x= config.variableName;
}
This will work

ashishraaj
- 751
- 7
- 27