Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you use AMD with Ember.js?

Tags:

amd

ember.js

When using Ember.js with AMD/Require.js, I notice that I cannot access my Ember.Application instance from the template unless I put it in the global scope (which is supposed to be the thing you avoid by using AMD).

Is it possible to define an Ember.Application without making it global?

My module:

define(['Ember'], function (Ember) {
    window.App = Ember.Application.create();
    App.MyView = Ember.View.extend({});
});

My template:

{{#view App.MyView }}{{/view}}
like image 301
hekevintran Avatar asked Feb 05 '26 02:02

hekevintran


1 Answers

There is a repo hosted here: https://bitbucket.org/cprecourt/ember-requirejs-example/src. This is an extensive application that lets you see how to handle separating your code. Em.Application is always global unless you decide to nest it inside the Ember object (which you are free to do, and the example repo does do it to allow templates to access the application).

Ember already dumps a load of objects into global before your app loads, so I don't see why a single object more in global is going to make a difference (opposed to polluting the Em/Ember global).

like image 182
DF_ Avatar answered Feb 09 '26 03:02

DF_



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!