ts-container-ability-component.md 2.1 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 8
>  This component is deprecated since API version 10. You are advised to use [\<UIExtensionComponent>](ts-container-ui-extension-component.md) instead.
>
E
ester.zhou 已提交
9
>  This component is supported since API version 9. Updates will be marked with a superscript to indicate their earliest API version.
E
ester.zhou 已提交
10
>
E
ester.zhou 已提交
11
>  The APIs provided by this component are system APIs.
E
ester.zhou 已提交
12 13 14 15 16 17 18 19 20

## 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.

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

## Child Components

Not supported


## APIs

E
ester.zhou 已提交
30
AbilityComponent(want: Want)
E
ester.zhou 已提交
31

32 33
**Parameters**

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


## Events

41 42
### onConnect

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

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

### onDisconnect

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

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

## Example

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

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