Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emberjs rootElement

Tags:

ember.js

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.

like image 387
kabra Avatar asked Jul 09 '12 16:07

kabra


1 Answers

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/

like image 106
Mike Aski Avatar answered Nov 08 '22 11:11

Mike Aski