# AUR0779

## Error Message

`AUR0779: Invalid portal insertion position: <position>`

Where `<position>` is the invalid value provided to the `position` bindable attribute of the `portal`.

## Description

This error occurs when using the `portal` template controller (often implicitly via the `portal` attribute) and providing an invalid value for the `position` bindable attribute. The `position` attribute determines where the portal's content should be inserted relative to its target element.

## Cause

The error is caused by setting the `position` attribute on a `portal` element or custom attribute to a string value other than the allowed options.

The valid values for the `position` attribute are:

* `'beforebegin'`: Before the target element itself.
* `'afterbegin'`: Just inside the target element, before its first child.
* `'beforeend'`: Just inside the target element, after its last child. (This is often the default)
* `'afterend'`: After the target element itself.

Any other string value provided will result in this error.

## Solution

1. **Check `position` Value:** Review the template where the `portal` attribute is used and ensure the value bound to the `position` attribute is one of the four valid strings: `'beforebegin'`, `'afterbegin'`, `'beforeend'`, or `'afterend'`.
2. **Verify Binding:** If the `position` is dynamically bound (e.g., `position.bind="myPosition"`), ensure that the view model property (`myPosition` in this case) always resolves to one of the valid strings.
3. **Default Behavior:** If you want the default behavior (usually `'beforeend'`), you can often omit the `position` attribute entirely, depending on the portal's configuration.

## Example

```html
<!-- Assume 'renderTarget' is an element reference -->

<!-- Incorrect: 'inside' is not a valid position -->
<template portal="target.bind: renderTarget; position: 'inside'">
  <div>My portal content</div>
</template>

<!-- Incorrect: Typo in position value -->
<template portal="target.bind: renderTarget; position: 'beforeEnd'"> <!-- Case-sensitive! -->
  <div>My portal content</div>
</template>

<!-- Correct: Using a valid position -->
<template portal="target.bind: renderTarget; position: 'afterbegin'">
  <div>My portal content</div>
</template>

<!-- Correct: Using binding with a valid value in the view model -->
<template portal="target.bind: renderTarget; position.bind: insertPosition">
  <div>My portal content</div>
</template>
```

```typescript
// View Model
import { customElement } from 'aurelia';

@customElement({ /* ... */ })
export class MyComponent {
  renderTarget: HTMLElement; // Assume this is assigned elsewhere
  insertPosition: 'beforebegin' | 'afterbegin' | 'beforeend' | 'afterend' = 'beforeend';

  // Ensure this property is always one of the valid strings
  // insertPosition = 'invalid'; // This would cause AUR0779
}
```

## Debugging Tips

* Inspect the DOM to verify the element targeted by the portal exists.
* Check the value being passed to the `position` attribute in the template.
* If bound, log the value of the view model property bound to `position` just before the portal attempts to render or move its content.
* Refer to the documentation for `Element.insertAdjacentHTML()` on MDN, as the `position` values correspond directly to its `position` parameter.

```
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.aurelia.io/developer-guides/error-messages/runtime-html/aur0779.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
