# Error when providing AppState to an embeded visualization

**URL:** <https://discuss.elastic.co/t/error-when-providing-appstate-to-an-embeded-visualization/106231>\
**Category:** Kibana\
**Created:** [November 2, 2017, 6:00pm UTC](https://discuss.elastic.co/t/error-when-providing-appstate-to-an-embeded-visualization/106231 "2017-11-02T18:00:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![havidarou](https://avatars.discourse-cdn.com/v4/letter/h/3ec8ea/32.png) [@havidarou](https://discuss.elastic.co/u/havidarou)\
**Post date:** [November 2, 2017, 6:00pm UTC](https://discuss.elastic.co/t/error-when-providing-appstate-to-an-embeded-visualization/106231/1 "2017-11-02T18:00:40Z")

</div>

Hi,

I am trying to provide an AppState to an embedded visualization:

```
visualizeLoader.embedVisualizationWithId(visContainer, $scope.selectedVisualization, {
      timeRange: timeRange, appState: AppState
    }).then(handler => {
      console.log('render complete');
    });

```

Being AppState included as a dependency in the controller:

`> app.controller('WebinarDemo', function ($scope, Private, savedVisualizations, AppState) {`

When I try to load it:

![image](https://us1.discourse-cdn.com/elastic/original/3X/0/2/02463e06e7f1d796a3695c023691a6dbba7f3766.png)

Am I doing something wrong? how do I go about this?

Regards.

---

<div class="post-metadata">

**Author:** ![havidarou](https://avatars.discourse-cdn.com/v4/letter/h/3ec8ea/32.png) [@havidarou](https://discuss.elastic.co/u/havidarou)\
**Post date:** [November 2, 2017, 7:45pm UTC](https://discuss.elastic.co/t/error-when-providing-appstate-to-an-embeded-visualization/106231/2 "2017-11-02T19:45:41Z")

</div>

I changed the AppState initialization like this (adding the getAppState service in my controller):

```
let currentAppState = getAppState();
  if (!currentAppState) {
      $scope.state = new AppState(getStateDefaults());
}

  function getStateDefaults() {
      return {
          query: '',
          index: 'c78aa9f0-bfec-11e7-bd67-eb6db07d9b4b',
          interval: 'auto',
          filters: {}
      };
  }

```

I'm using some hardcoded defaults for the appState initialization.

Then I use it as param in my embed visualization:

```
  $scope.$watch('selectedVisualization', () => {
    if (!$scope.selectedVisualization) return;
    visualizeLoader.embedVisualizationWithId(visContainer, $scope.selectedVisualization, {
      timeRange: timeRange, appState: $scope.state
    }).then(handler => {
      console.log('render complete');
    });
  });

```

But it's not affecting at all the visualization.

Regards.

---

<div class="post-metadata">

**Author:** ![weltenwort](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/weltenwort/32/53885_2.png) [@weltenwort](https://discuss.elastic.co/u/weltenwort)\
**Post date:** [November 3, 2017, 11:24am UTC](https://discuss.elastic.co/t/error-when-providing-appstate-to-an-embeded-visualization/106231/3 "2017-11-03T11:24:27Z")

</div>

It's nice to see that you are trying to build on the examples of one of the webinars. I will try to get the visualization team in here, because they can probably help you much more competently.

---

<div class="post-metadata">

**Author:** ![havidarou](https://avatars.discourse-cdn.com/v4/letter/h/3ec8ea/32.png) [@havidarou](https://discuss.elastic.co/u/havidarou)\
**Post date:** [November 3, 2017, 11:25am UTC](https://discuss.elastic.co/t/error-when-providing-appstate-to-an-embeded-visualization/106231/4 "2017-11-03T11:25:39Z")

</div>

@weltenwort thanks!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 1, 2017, 11:25am UTC](https://discuss.elastic.co/t/error-when-providing-appstate-to-an-embeded-visualization/106231/5 "2017-12-01T11:25:43Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
