ts-container-ability-component.md 1.9 KB
Newer Older
E
ester.zhou 已提交
1 2
# AbilityComponent

E
ester.zhou 已提交
3 4
**\<AbilityComponent>** is a container for independently displaying an ability.

E
ester.zhou 已提交
5 6
>  **NOTE**
>
E
ester.zhou 已提交
7
>  The APIs of this module are supported since API version 9. Updates will be marked with a superscript to indicate their earliest API version.
E
ester.zhou 已提交
8 9 10 11 12 13 14 15 16 17 18
>
>  The APIs of this module are system APIs and cannot be called by third-party applications.

## Constraints

**\<AbilityComponent>** is rendered independently and cannot be overlaid with other display content.

**\<AbilityComponent>** cannot process input events. Events are directly distributed to the internal ability for processing without passing through the current ability.

Only width and height can be set for **\<AbilityComponent>**. These attributes are mandatory and cannot be dynamically updated.

19
The ability to be started must inherit from [WindowExtension](../apis/js-apis-application-WindowExtensionAbility.md).
E
ester.zhou 已提交
20 21 22 23 24 25 26 27

## Child Components

Not supported


## APIs

E
ester.zhou 已提交
28
AbilityComponent(want: Want)
E
ester.zhou 已提交
29

30 31
**Parameters**

E
ester.zhou 已提交
32 33 34
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](../apis/js-apis-application-Want.md) | Yes| Description of the default ability to load.|
E
ester.zhou 已提交
35 36 37 38


## Events

39 40
### onConnect

E
ester.zhou 已提交
41
onConnect(callback:() =&gt; void)
42 43 44 45 46

Called when this **\<AbilityComponent>** is started. You can then use APIs in the **\<AbilityComponent>**.

### onDisconnect

E
ester.zhou 已提交
47
onDisconnect(callback:() =&gt; void)
E
ester.zhou 已提交
48

49
Called when this **\<AbilityComponent>** is destroyed.
E
ester.zhou 已提交
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66

## Example

```ts
// xxx.ets
@Entry
@Component
struct MyComponent {

  build() {
      Column() {
          AbilityComponent({
              want: {
                  bundleName: '',
                  abilityName: ''
              },
          })
E
ester.zhou 已提交
67 68
          .onConnect(() => {
              console.log('AbilityComponent connect');
E
ester.zhou 已提交
69
          })
E
ester.zhou 已提交
70 71
          .onDisconnect(() => {
              console.log('AbilityComponent disconnect');
E
ester.zhou 已提交
72 73 74 75 76
          })
      }
  }
}
```