Private in app plugin?

I am developing an app plugin which needs to see the currently pinned filters. A previous post of mine and many searches reconfirm that I need to be using 'ui/filter_bar/filter_bar' but every reference I found to that calls Private(), which seems to be a parameter frequently passed to visualizations. My app does not get passed it and produces a "private is undefined" error.

Where does this come from and how can I receive this parameter, import it, or define it in an app?

First, about Private: this is an angular service that is responsible for taking anonymous providers like https://github.com/elastic/kibana/blob/4bbd127626e2a74d7fa75fc73ce69c2331938c28/src/ui/public/agg_response/tabify/tabify.js#L5. It instantiates services much like angular.module().service(name, provider) does, except it doesn't require picking a name for the service and instead uses the provider as the key, requiring that you import the provider to get it's instance.

To get an instance of the Private service in your app you'll need to inject it somewhere like in your controller of directives:

import { uiModules } from 'ui/modules'
const module = uiModules.get('myModule')
module.service('myService', function (Private) {
  // Here you can use Private to get the instance of anonymous providers
});

For more information about Private checkout the docs in this file: https://github.com/elastic/kibana/blob/master/src/ui/public/private/private.js


I think the service you want is ui/filter_bar/query_filter source. You will need the Private loader to get access to this service, and it will look something like this:

import { FilterBarQueryFilterProvider } from 'ui/filter_bar/query_filter';
import { uiModules } from 'ui/modules';

uiModules.compoent('myComponent', function (Private) { 
  return {
    template: `
      <pre>{{$ctrl.globalFilters | json}}</pre>
    `,
    controller() {
      const filterBarQueryFilter = Private(FilterBarQueryFilterProvider);

      this.globalFilters = filterBarQueryFilter.getGlobalFilters()
    }
  }
});

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