Question

I've been during a while working with Ember.js. Now I'm getting a weird behaviour that I cannot fix. Is not the first time I experience it, but in previous occasions I figured it out after making little changes. But now, I really have no idea what's causing the conflict. The issue is occuring in Controllers. I have this ridiculously simple controller, just for testing:

App.AppColleaguesController = Ember.ArrayController.extend
(
  {
    needs: ['app'],

    aNumber: function()
    {
      return this.get('controllers.app.personId');
    }
  }
);

Of course, that property is defined on the AppController:

App.AppController = Ember.ArrayController.extend
(
  {
    loggedIn: false,
    personId: -1,
    personName: '',
    location: '',

    logOut: function()
    {
      if (window.confirm("Do you want log out?"))
      {
        this.set('loggedIn', false);
        this.set('personId', -1);
        this.set('personName', '');
        this.set('location', '');
        this.send('goToLogin');
      }
    }
  }
);

In my template, I'm getting this result:

... This is a number: function () { return this.get('controllers.app.personId'); } ...

My template is as straightforward as this:

...
This is a number: *{{aNumber}}*

{{debug}}
{{log aNumber}}
...

The debugging statements in my template are showing me this in Firebug console:

...
Transitioned into 'app.colleagues'
function()
...

So, is like the function is literally echoed, not "interpreted". In fact I'm getting this sort of problem in a couple more of controllers, but the rest of them (they are a lot, like 8 or 10 controllers) are working nice. Do you have any idea about the problem? Is my mistake, or maybe an Ember issue?

Thanks a lot in advance! I hope you can help me.

Was it helpful?

Solution

You forgot the .property after the function. This is needed by Ember to indicate that a function is a computed property.

aNumber: function() {
  return this.get('controllers.app.personId');
}.property('app.personId')
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top