Reputation: 152
It seems that when I use the new routing feature in Ember.js the properties and action handlers defined on a view is not accessible from its template. Instead, only properties of the controller is available and the app looks for action handlers in the router.
Here is an example of the problem: http://jsfiddle.net/InMatrix/wtUML/3/
If you click My Profile ---> Photos ---> test, you'll get this error in the console:
could not respond to event testButton in state root.profile.photos.
Apparently the following action handler defined in App.PhotosView is not available to the event.
App.PhotosView = Em.View.extend({
templateName: 'photos',
testButton: function(){
alert('test Button');
}
});
Is there a way I can keep my action handlers in the relevant view class? Did I miss anything?
Upvotes: 1
Views: 362
Reputation: 1833
@buuda nailed it but in case you want to read more, see the embedded documentation for the action helper:
https://github.com/emberjs/ember.js/blob/master/packages/ember-handlebars/lib/helpers/action.js
Upvotes: 1
Reputation: 1427
The default context of actions have been changed to the router. If you want the view to handle actions you need to specify it like this:
<button {{action testButton target="view"}}>test</button>
Here is a working version of your fiddle: http://jsfiddle.net/wtUML/4/
Upvotes: 3