I have http://jsfiddle.net/pF2cF/6/ code with 2 problems: 1. click "MyButton" doesn't go to clickButton function in App.indexController 2. enter in the text field will trigger MyButton click first (if #1 get solved)
Can anyone help to solve them? I do have a workaround for by using , but I'm not sure what's wrong with using.
Thanks!
The code snippets are as following, using ember.js from its master branch on 01/14/2013:
<script type="text/x-handlebars" data-template-name="myTemplate">
<button {{action clickButton target="App.indexController"}} >MyButton1</button>
{{view App.MyView placeholder="Input something 1 and enter"}}
</script>
App = Em.Application.create({
ready: function () {
}
});
App.Router.map(function () {
this.route("index", { path: "/" }); //master 01142013 syntax
});
App.IndexRoute = Ember.Route.extend({
renderTemplate: function () {
this.render('myTemplate', {controller: 'indexController'});
}
});
App.indexController = Ember.Controller.extend({
clickButton: function () {
alert("clickButton");
}
});
App.MyView = Em.TextField.extend({
insertNewline: function (evt) {
alert("enter pressed");
}
});
Passing the Action to the Componentimport Component from '@ember/component'; export default Component. extend({ actions: { launchConfirmDialog() { this. set('confirmShown', true); }, submitConfirm() { //call the onConfirm property to invoke the passed in action this.
What are Ember closure actions? Ember closure actions are based on JavaScript closures which are basically functions that remember environment in which they were created. So closure actions are just functions that remember context in which they were defined.
The parent can then use this reference to the child component to call its function whenever required. I decided to place the sendAction call inside didInsertElement hook of the child element to register itself with the parent component as soon as it is added to the parent DOM. Following is the gist to the solution.
Ember. js is a frontend web framework which claims on its website, to be the one tool you will need to build an ambitious web application.
You made a number of small errors. I have put a working version on JSBin.
Stylistic issues that did not cause any failures:
index
routes.ready
method on Application
. In general, put startup logic in ApplicationRoute#setupController
, where you will also have access to controllers.index
rather than myTemplate
.Issues related to the failures:
App.IndexController
not App.indexController
render
call specifies { controller: 'indexController' }
. It should be { controller: 'index' }
.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With