Skip to content

Instantly share code, notes, and snippets.

@jayphelps
Created July 19, 2013 05:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jayphelps/6036938 to your computer and use it in GitHub Desktop.
Save jayphelps/6036938 to your computer and use it in GitHub Desktop.
Intro to Ember.js - Demo app from the Ember meetup presentation Slides: http://www.slideshare.net/jayphelps/intro-to-emberjs-24409989
<!DOCTYPE html>
<html>
<body>
<script type="text/x-handlebars">
<h1>My Great Web App</h1>
<div>
{{outlet}}
</div>
</script>
<script type="text/x-handlebars" data-template-name="index">
<h1>{{welcomeMessage}}</h1>
<ul>
{{#each names}}
<li>{{this}}</li>
{{/each}}
</ul>
{{#linkTo about}}Navigate to `about` page{{/linkTo}}
</script>
<script type="text/x-handlebars" data-template-name="about">
<p>The current time is: {{time}}</p>
{{#linkTo index}}Navigate to `index` (home) page{{/linkTo}}
</script>
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="http://builds.emberjs.com/handlebars-1.0.0-rc.4.js"></script>
<script src="http://builds.emberjs.com/ember-1.0.0-rc.6.min.js"></script>
<script>
var App = Ember.Application.create();
App.Router.map(function () {
// route ‘index’ is auto-assumed
this.route('about');
this.route('contact');
});
App.IndexRoute = Ember.Route.extend({
setupController: function (controller) {
controller.set('welcomeMessage', 'Welcome!');
}
});
App.AboutRoute = Ember.Route.extend({
setupController: function (controller) {
setInterval(function () {
controller.set('time', new Date());
}, 1000);
}
});
App.IndexController = Ember.ObjectController.extend({
welcomeMessage: '',
names: ['Bilbo', 'Frodo', 'Sam']
});
App.AboutView = Ember.View.extend({
// template name is optional for views
// that are rendered from a route
templateName: 'about',
// events bubble up to each parent view until it reaches
// the root view
click: function (event) {
alert('about view clicked!');
}
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment