Javed Akhtar
Javed Akhtar

Reputation: 287

Getting started with Ember.js

I didn't find any good documentation for getting started with the Ember.js. Please help me, Here is a simple example i tried from http://emberjs.com/documentation/ But nothing displayed on screen.

Error:  MyApp is not defined  

Javascript: app.js

    MyApp.president = Ember.Object.create({
  firstName: "Barack",
  lastName: "Obama",
  fullName: function() {
    return this.get('firstName') + ' ' + this.get('lastName');
  // Tell Ember that this computed property depends on firstName
  // and lastName
  }.property('firstName', 'lastName')
});

HTML

<p>
<script type="text/x-handlebars">
  The President of the United States is {{MyApp.president.fullName}}.
</script>
</p>

I included all the JS files from the getting started Kit.

Upvotes: 5

Views: 773

Answers (2)

user1936059
user1936059

Reputation:

You've forgot to define MyApp, which has to be an instance of Ember.Application:

var MyApp = Ember.Application.create({});

Here is one very comprehensive tutorial I've found few weeks ago, maybe it would be useful for your learning purposes: http://www.appliness.com/flame-on-a-beginners-guide-to-ember-js/

Upvotes: 6

You have to define MyApp

I have created a working example here. Click the Run button to see the result.

HTML

<p>
<script type="text/x-handlebars">
  The President of the United States is {{MyApp.president.fullName}}.
</script>
</p>​

Code

window.MyApp = Ember.Application.create();

MyApp.president = Ember.Object.create({
  firstName: "Barack",
  lastName: "Obama",
  fullName: function() {
    return this.get('firstName') + ' ' + this.get('lastName');
  }.property('firstName', 'lastName')
});
​

Upvotes: 4

Related Questions