• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Event Configuration
2
3
4You can use event methods to configure events supported by components.
5
6
7- Example of using a lambda expression to configure the event of a component:
8
9  ```
10  // Counter is a private data variable defined in the component.
11  Button('add counter')
12      .onClick(() => {
13          this.counter += 2
14      })
15  ```
16
17
18- When using an anonymous function expression to configure the event of a component, bind must be used to ensure that the contained components are referenced by this in the function body.
19
20  ```
21  // Counter is a private data variable defined in the component.
22  Button('add counter')
23      .onClick(function () {
24          this.counter += 2
25      }.bind(this))
26  ```
27
28
29- Example of using a component's member function to configure the event of the component:
30
31  ```
32  myClickHandler(): void {
33      // do something
34  }
35
36  ...
37
38  Button('add counter')
39    .onClick(this.myClickHandler)
40  ```
41