kabra
kabra

Reputation: 1316

Emberjs rootElement

In guide I can find:

" If you are embedding an Ember application into an existing site, you can have event listeners set up for a specific element by providing a rootElement property:

window.App = Ember.Application.create({
  rootElement: '#sidebar'
});

"

Please give me example how to use it corretly.

Upvotes: 8

Views: 3681

Answers (1)

Mike Aski
Mike Aski

Reputation: 9236

HTML

<script type="text/x-handlebars" data-template-name="app-view">
    My ember app view
</script>

This is a static content

<div id="app-container"></div>

This is a static content

JS

App = Ember.Application.create({
  rootElement: '#app-container'
});

App.ApplicationController = Ember.Controller.extend();
App.ApplicationView = Ember.View.extend({
    templateName: 'app-view'
});

App.Router = Ember.Router.extend({
    root: Ember.Route.extend({
        index: Ember.Route.extend({
            route: '/',

            connectOutlets: function (router) {
                // do some stuff here...
            }
        })
    })
});

App.initialize();

Here is the JSFiddle: http://jsfiddle.net/MikeAski/xtzNB/

Upvotes: 24

Related Questions