Static properties throughout the app


#1

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


#2

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 https://ember-twiddle.com/e13e89b5956b366b9345?numColumns=3&openFiles=my-component.component.js%2Capplication.controller.js%2Capplication.template.hbs

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()

#3

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


#4

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.

https://ember-twiddle.com/488e5a759c956dfa2375?numColumns=3&openFiles=models.my-model.js%2Capplication.controller.js%2Capplication.template.hbs


#5

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