Reputation: 997
I have defined a custom template helper similar to what they show in the Ember guides.
Ember.Handlebars.registerBoundHelper('fullName', function(person) {
return person.get('firstName') + ' ' + person.get('lastName');
}, 'firstName', 'lastName');
Yet, every time I load the page, I get a strange error:
Uncaught TypeError: Cannot read property '0' of null
I tried to track it down, and I wonder if it could be a context issue. Indeed, when I break in Ember.Handlebars.registerBoundHelper, I can see that the observers that it is trying to register for 'firstName' and 'lastName' do not have a proper path. They are ".firstName" and ".lastName" which does not mean anything...
Do you have any idea what might be happening?
Also, I should add: if I remove the dependencies:
Ember.Handlebars.registerBoundHelper('fullName', function(person) {
return person.get('firstName') + ' ' + person.get('lastName');
});
I can break in my helper. When I do person.toString(), it seems "normal" (with the right ID, etc), yet, when I do person.get('firstName') in the console I get null, as if the record had not completely loaded. Strange.
Thanks
PJ
Upvotes: 1
Views: 331
Reputation: 1506
This bug is a bug (https://github.com/emberjs/ember.js/issues/2948) I provided fix for this: https://github.com/seeweer/ember.js/commit/0226e1c605f84e469e56c7c397599a4295946094
This bug was caused by this
on handlebar helper.
For example if you have such template:
{{someHelper this}}
Then instead of this
you can use for example view.context
if you are in the view or controller
if you are in the controller.
Upvotes: 1
Reputation: 997
In case it helps other people: it was a context issue. It is a bit weird since "person" within the helper was indeed an App.Person. But I tried various context shifts and it ended up working (it might be because I am on master?). So in case you hit a strange behaviour like this, you might want to double check what context you are passing to the helper.
Upvotes: 1