Skip to content

Instantly share code, notes, and snippets.

@phillipkregg
Last active July 20, 2016 07:40
Show Gist options
  • Save phillipkregg/51802332e4f395f979fb3a0a68184138 to your computer and use it in GitHub Desktop.
Save phillipkregg/51802332e4f395f979fb3a0a68184138 to your computer and use it in GitHub Desktop.
Application-Level Component
import Ember from 'ember';
export default Ember.Component.extend({
didInsertElement: function() {
// any JS inits that need to happen
// universally can be called here.
//
// For example if you need to register
// bootstrap dropdowns, you can do something
// like $('.dropdown-toggle').dropdown()
// from here and it will work everywhere
// there is a dropdown.
alert('yay, dom is ready!')
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Wrap Your App in a Component!'
});
body {
margin: 12px 16px;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 12pt;
}
<h1>{{appName}}</h1>
<p>In application.js you can use the didRender or didInsertElement hooks of this component to make any calls that need to happen universally to all components or views - such as jQuery inits for Bootstrap or other libraries</p>
{{#application-area}}
{{outlet}}
{{/application-area}}
<div style="border: 1px solid green; padding: 10px;">
{{!-- All templates in the app will be rendered in the yield --}}
{{yield}}
</div>
<h3>This is the main Index template</h3>
<h5>... rendered through the application-area component's 'yield' statement</h5>
<h5>All other pages will be rendered through this component as well since it is wrapping the main handlebars outlet helper.</h5>
{
"version": "0.10.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.6.0",
"ember-data": "2.6.1",
"ember-template-compiler": "2.6.0"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment