Using this example: jsbin
Where would I put this line of code:
App.name = 'White'
in the EAK file structure so that it will render on the index page as in the example?
Ember components are used to turn markup text and styles into reusable content. Components consist of two parts: a JavaScript component file that defines behavior, and its accompanying Handlebars template that defines the markup for the component's UI. Components must have at least one dash in their name.
To define a new Ember class, call the extend() method on EmberObject : import EmberObject from '@ember/object'; const Person = EmberObject. extend({ say(thing) { alert(thing); } }); This defines a new Person class with a say() method.
I'm not sure if this is the right way. But generally EAK tries to avoid polluting the global namespace. So a method to have globals accessible every where is to use initializers to register a globals dependency and inject them to all the controllers. This is the same way ember data injects the store to the controller.
Inside app/initializers
create global.js
file
var globals = Ember.Object.extend({
name: 'Edgar Allen Poe'
});
export default {
name: "Globals",
initialize: function(container, application) {
container.typeInjection('component', 'store', 'store:main');
application.register('global:variables', globals, {singleton: true});
application.inject('controller', 'globals', 'global:variables');
}
};
This will inject the globals to all the controllers. You can refer it in a template like
{{globals.name}}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With