As I develop my Ember application with the Ember CLI, I encountered an issue while trying to access the global App variable in order to create and insert a component into my layout. The error message I received was "Uncaught ReferenceError: App is not defined."
How can I resolve this issue?
app.js
import Ember from 'ember';
import Resolver from 'ember/resolver';
import loadInitializers from 'ember/load-initializers';
Ember.MODEL_FACTORY_INJECTIONS = true;
var App = Ember.Application.extend({
modulePrefix: 'client-web', // TODO: loaded via config
Resolver: Resolver
});
loadInitializers(App, 'client-web');
export default App;
item-table.js (This serves as a view)
import Ember from 'ember';
export default Ember.View.extend({
templateName: 'item-table',
didInsertElement: function() {
// Inserting other code here
App.FreestyleChartComponent.create().appendTo($('#wp-chart td')); // This line throws an error.
}
});
app/components/freestyle-chart.js
import Ember from 'ember';
export default Ember.Component.extend({
templateName: 'components/freestyle-chart',
didInsertElement: function() {
console.log('Successfully inserted the component.');
}
});