简体   繁体   中英

Ember global App variable

I am developing my Ember as an addon & inside my tests\\dummy\\app.js, I have

App = Ember.Application.extend({
  modulePrefix: config.modulePrefix,
});

My question is related to accessing global variable acrosss the Ember app.

Do I have to do

window.App = App;

in the above place only (ie where I'll have Ember.Application.extend())

OR can I do in some other place as well ?

You can define a class in a js file such as:

import Ember from 'ember';

const MyClazz = Ember.Object.extend({
    // your properties and methods
});

const myObj = MyClazz.create({});
export default myObj;

This object will behave as a global object and you can access this object from anywhere you want like that:

import MyObj from '/...path';
...

MyObj.get('...');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM