Static properties throughout the app

Dear Members,

I want to access few properties from anywhere in the app, say: myAppName, I want this property in route and components. Please give standard way out to do so in ember 2.3.

Also, plz tell how to make a model which may hold global properties and can be imported and used in .js and .hbs files direcly say, myAppName in {{abc.myAppName}} where abc is

import abc from ‘…/…/’;

Regards

Dn

I want this property in route and components. Please give standard way out to do so in ember 2.3.

Standard way is by using services. Here’s an example Ember Twiddle

You need to:

  • Create your own service by extending Ember.Service
  • Whenever you need service in your controller/route/component inject it by using Ember.inject.service()

If you mean static properties like your app name you can also use the configuration.

If you use a service you can globally inject it with an InstanceInitializer

Dear Sir,

Please go through this example where I created a model my-model and made it static by added .create() at the end. And I am importing the model and using the properties as global. Is it a correct or standard way or not. please tell.

@Deepak_Negi_Sunny Dont do this! You make it as singleton, but you should use the DI container for that. Use a service!