2020-02-26 03:03:53 -06:00
|
|
|
+++
|
|
|
|
# -----------------------------------------------------------------------
|
|
|
|
# Do not edit this file. It is automatically generated by API Documenter.
|
|
|
|
# -----------------------------------------------------------------------
|
|
|
|
title = "AngularComponent"
|
|
|
|
keywords = ["grafana","documentation","sdk","@grafana/runtime"]
|
|
|
|
type = "docs"
|
|
|
|
+++
|
|
|
|
|
|
|
|
## AngularComponent interface
|
|
|
|
|
2020-04-21 03:41:50 -05:00
|
|
|
Used to enable rendering of Angular components within a React component without losing proper typings.
|
|
|
|
|
2020-02-26 03:03:53 -06:00
|
|
|
<b>Signature</b>
|
|
|
|
|
|
|
|
```typescript
|
|
|
|
export interface AngularComponent
|
|
|
|
```
|
|
|
|
<b>Import</b>
|
|
|
|
|
|
|
|
```typescript
|
|
|
|
import { AngularComponent } from '@grafana/runtime';
|
|
|
|
```
|
2020-04-21 03:41:50 -05:00
|
|
|
|
|
|
|
## Example
|
|
|
|
|
|
|
|
|
|
|
|
```typescript
|
|
|
|
class Component extends PureComponent<Props> {
|
|
|
|
element: HTMLElement;
|
|
|
|
angularComponent: AngularComponent;
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
const template = '<angular-component />' // angular template here;
|
|
|
|
const scopeProps = { ctrl: angularController }; // angular scope properties here
|
|
|
|
const loader = getAngularLoader();
|
|
|
|
this.angularComponent = loader.load(this.element, scopeProps, template);
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
if (this.angularComponent) {
|
|
|
|
this.angularComponent.destroy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<div ref={element => (this.element = element)} />
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
```
|
|
|
|
|
2020-02-26 03:03:53 -06:00
|
|
|
<b>Methods</b>
|
|
|
|
|
|
|
|
| Method | Description |
|
|
|
|
| --- | --- |
|
2020-04-21 03:41:50 -05:00
|
|
|
| [destroy()](#destroy-method) | Should be called when the React component will unmount. |
|
|
|
|
| [digest()](#digest-method) | Can be used to trigger a re-render of the Angular component. |
|
|
|
|
| [getScope()](#getscope-method) | Used to access the Angular scope from the React component. |
|
2020-02-26 03:03:53 -06:00
|
|
|
|
|
|
|
### destroy method
|
|
|
|
|
2020-04-21 03:41:50 -05:00
|
|
|
Should be called when the React component will unmount.
|
|
|
|
|
2020-02-26 03:03:53 -06:00
|
|
|
<b>Signature</b>
|
|
|
|
|
|
|
|
```typescript
|
|
|
|
destroy(): void;
|
|
|
|
```
|
|
|
|
<b>Returns:</b>
|
|
|
|
|
|
|
|
`void`
|
|
|
|
|
|
|
|
### digest method
|
|
|
|
|
2020-04-21 03:41:50 -05:00
|
|
|
Can be used to trigger a re-render of the Angular component.
|
|
|
|
|
2020-02-26 03:03:53 -06:00
|
|
|
<b>Signature</b>
|
|
|
|
|
|
|
|
```typescript
|
|
|
|
digest(): void;
|
|
|
|
```
|
|
|
|
<b>Returns:</b>
|
|
|
|
|
|
|
|
`void`
|
|
|
|
|
|
|
|
### getScope method
|
|
|
|
|
2020-04-21 03:41:50 -05:00
|
|
|
Used to access the Angular scope from the React component.
|
|
|
|
|
2020-02-26 03:03:53 -06:00
|
|
|
<b>Signature</b>
|
|
|
|
|
|
|
|
```typescript
|
|
|
|
getScope(): any;
|
|
|
|
```
|
|
|
|
<b>Returns:</b>
|
|
|
|
|
|
|
|
`any`
|
|
|
|
|