@@ -205,8 +205,8 @@ declare const SIGNATURE: unique symbol;
205205 default for older editions of Ember (pre 3.15).
206206
207207 Below is the documentation for Classic components. If you are looking for the
208- API documentation for Template-only or Glimmer components, it is
209- [available here](/ember/release/modules/@glimmer%2Fcomponent).
208+ API documentation for Template-only or Glimmer components, it is [available
209+ here](/ember/release/modules/@glimmer%2Fcomponent).
210210
211211 ## Defining a Classic Component
212212
@@ -404,9 +404,9 @@ declare const SIGNATURE: unique symbol;
404404 <div id="ember1" class="ember-view empty"></div>
405405 ```
406406
407- If you want to add a class name for a property which evaluates to true and
408- and a different class name if it evaluates to false, you can pass a binding
409- like this:
407+ If you want to add a class name for a property which evaluates to true and and
408+ a different class name if it evaluates to false, you can pass a binding like
409+ this:
410410
411411 ```app/components/my-widget.js
412412 import Component from '@ember/component';
@@ -467,9 +467,9 @@ declare const SIGNATURE: unique symbol;
467467 ### Other HTML Attributes
468468
469469 The HTML attribute section of a component's tag can be set by providing an
470- `attributeBindings` property set to an array of property names on the component.
471- The return value of these properties will be used as the value of the component's
472- HTML associated attribute:
470+ `attributeBindings` property set to an array of property names on the
471+ component. The return value of these properties will be used as the value of
472+ the component's HTML associated attribute:
473473
474474 ```app/components/my-anchor.js
475475 import Component from '@ember/component';
@@ -488,8 +488,8 @@ declare const SIGNATURE: unique symbol;
488488 <a id="ember1" class="ember-view" href="http://google.com"></a>
489489 ```
490490
491- One property can be mapped on to another by placing a ":" between
492- the source property and the destination property:
491+ One property can be mapped on to another by placing a ":" between the source
492+ property and the destination property:
493493
494494 ```app/components/my-anchor.js
495495 import Component from '@ember/component';
@@ -522,9 +522,9 @@ declare const SIGNATURE: unique symbol;
522522 <a id="ember1" class="ember-view" href="http://bing.com"></a>
523523 ```
524524
525- Note that the `href` attribute is ultimately set to `http://bing.com`,
526- despite it having attribute binidng to the `url` property, which was
527- set to `http://google.com`.
525+ Note that the `href` attribute is ultimately set to `http://bing.com`, despite
526+ it having attribute binidng to the `url` property, which was set to
527+ `http://google.com`.
528528
529529 Namespaced attributes (e.g. `xlink:href`) are supported, but have to be
530530 mapped, since `:` is not a valid character for properties in Javascript:
@@ -662,27 +662,33 @@ declare const SIGNATURE: unique symbol;
662662
663663 ## Handling Browser Events
664664
665- Components can respond to user-initiated events in one of three ways: passing
666- actions with angle bracket invocation, adding event handler methods to the
667- component's class, or adding actions to the component's template.
665+ There are two ways to handle user-initiated events:
668666
669- ### Passing Actions With Angle Bracket Invocation
667+ ### Using the `on` modifier to capture browser events
670668
671- For one-off events specific to particular instance of a component, it is possible
672- to pass actions to the component's element using angle bracket invocation syntax.
669+ In a component's template, you can attach an event handler to any element with the `on` modifier:
673670
674671 ```handlebars
675- <MyWidget {{action 'firstWidgetClicked'}} />
676-
677- <MyWidget {{action 'secondWidgetClicked'}} />
672+ <button {{on 'click' this.doSomething}} />
678673 ```
679674
680- In this case, when the first component is clicked on, Ember will invoke the
681- `firstWidgetClicked` action. When the second component is clicked on, Ember
682- will invoke the `secondWidgetClicked` action instead.
675+ This will call the function on your component:
676+
677+ ```js
678+ import Component from '@ember/component';
679+
680+ export default class ExampleComponent extends Component {
681+ doSomething = (event) => {
682+ // `event` is the native click Event
683+ console.log('clicked on the button');
684+ };
685+ });
686+ ```
683687
684- Besides `{{action}}`, it is also possible to pass any arbitrary element modifiers
685- using the angle bracket invocation syntax.
688+ See the [Guide on Component event
689+ handlers](https://guides.emberjs.com/release/components/component-state-and-actions/#toc_html-modifiers-and-actions)
690+ and the [API docs for `on`](../Ember.Templates.helpers/methods/on?anchor=on)
691+ for more details.
686692
687693 ### Event Handler Methods
688694
@@ -752,43 +758,6 @@ declare const SIGNATURE: unique symbol;
752758 * `dragEnd`
753759 * `drop`
754760
755- ### `{{action}}` Helper
756-
757- Instead of handling all events of a particular type anywhere inside the
758- component's element, you may instead want to limit it to a particular
759- element in the component's template. In this case, it would be more
760- convenient to implement an action instead.
761-
762- For example, you could implement the action `hello` for the `person-profile`
763- component:
764-
765- ```app/components/person-profile.js
766- import Component from '@ember/component';
767-
768- export default Component.extend({
769- actions: {
770- hello(name) {
771- console.log("Hello", name);
772- }
773- }
774- });
775- ```
776-
777- And then use it in the component's template:
778-
779- ```app/templates/components/person-profile.hbs
780- <h1>{{@person.name }}</h1>
781-
782- <button {{action 'hello' @person.name }}>
783- Say Hello to {{@person.name }}
784- </button>
785- ```
786-
787- When the user clicks the button, Ember will invoke the `hello` action,
788- passing in the current value of `@person.name` as an argument.
789-
790- See [Ember.Templates.helpers.action](/ember/release/classes/Ember.Templates.helpers/methods/action?anchor=action).
791-
792761 @class Component
793762 @extends Ember.CoreView
794763 @uses Ember.TargetActionSupport
0 commit comments