> ## Documentation Index
> Fetch the complete documentation index at: https://doc.lucidworks.com/llms.txt
> Use this file to discover all available pages before exploring further.

# ModalService

export const LwTemplate = ({title = "Key questions to get you started", icon = "sparkles", cta = "Powered by Agent Studio", linkHref = "https://lucidworks.com/demo/?utm_source=docs&utm_medium=referral&utm_campaign=docs_cta_ai"}) => {
  const [isLoaded, setIsLoaded] = useState(false);
  useEffect(() => {
    const timer = setTimeout(() => {
      setIsLoaded(true);
    }, 500);
    return () => clearTimeout(timer);
  }, []);
  return <div className="lw-template-container">
      <Card title={title} icon={icon}>
        {isLoaded && <span dangerouslySetInnerHTML={{
    __html: `<lw-template id="a029c1a9-28be-427e-b0e1-5d918920246a"></lw-template
            >`
  }} />}
        <Link href={linkHref} className="agent-studio-link text-left text-gray-600 gap-2 dark:text-gray-400 text-sm font-medium flex flex-row items-center hover:text-primary dark:hover:text-primary-light group-hover:text-primary group-hover:dark:text-primary-light">Powered by Lucidworks Agent Studio</Link>
      </Card>
    </div>;
};

[localhost link]: http://localhost:3000/docs/5/app-studio/reference/services/lightning.ModalService

[mintlify link]: https://doc.lucidworks.com/docs/5/app-studio/reference/services/lightning.ModalService

[old doc.lw link]: https://doc.lucidworks.com/app-studio/4.2/1221

<LwTemplate />

## Description

Twigkit service for registering and un-registering modals

## Methods

### close(name)

Hides the modal in the view.

#### Parameters

| Param | Type   | Details                        |
| ----- | ------ | ------------------------------ |
| name  | string | The ID of the modal to remove. |

#### Example

```js wrap  theme={"dark"}
ModalService.close(name);
```

### onClose(name, callback, scope)

When the modal's close event is fired the callback function will be called.

#### Parameters

| Param    | Type     | Details                                                                          |
| -------- | -------- | -------------------------------------------------------------------------------- |
| name     | string   | The name of the modal, if null the callback will fire whenever a modal is closed |
| callback | Function | The function to be called when the cancel event is fired.                        |
| scope    | Object   | The `$scope` object for unsubscribing to the event when the scope is destroyed.  |

#### Example

```js wrap  theme={"dark"}
ModalService.onClose('MyModal', function (modalId) {
  console.log('Modal: 'modalId + ' has been closed');
}, $scope);
ModalService.close('my_modal');
```

### register(modal)

Registers the modal to the factory

#### Parameters

| Param | Type   | Details           |
| ----- | ------ | ----------------- |
| modal | string | The modal object. |

#### Example

```js wrap  theme={"dark"}
ModalService.register(modal);
```

### show(name)

Shows the modal in the view.

#### Parameters

| Param | Type   | Details                        |
| ----- | ------ | ------------------------------ |
| name  | string | The ID of the modal to remove. |

#### Example

```js wrap  theme={"dark"}
ModalService.show(name);
```

### unregister(name)

Un-registers the modal removing it from the view and the factory.

#### Parameters

| Param | Type   | Details                        |
| ----- | ------ | ------------------------------ |
| name  | string | The ID of the modal to remove. |

#### Example

```js wrap  theme={"dark"}
ModalService.unregister(name);
```
