Created
July 19, 2013 05:50
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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