Using external angular module in plugin


#1

Hi
Is it possible to use external angular module exposed by a library in Grafana plugins? It needs to be added to dependencies of some existing module (e.g. grafana.directives), but unfortunately that’s not possible since grafana modules are already defined and created. I tried some hacks from https://stackoverflow.com/questions/18875714/re-open-and-add-dependencies-to-an-already-bootstrapped-application but it didn’t work for me.
In fact I’m trying to use ng-tags-input which exposes “ngTagsInput” module.


#2

grafana already contains a tags directive in bootstrap-tagsinput

https://github.com/grafana/grafana/blob/master/public/app/features/dashboard/partials/settings.html#L37

if you want to create a seperate angular module with dependencies do that and then import app from ‘app/app’; then use app.useModule(yourNewModule);


#3

I tried to inject simple module (with one simple directive) using app.useModule. It got registered, but the directive wasn’t rendered. I guess useModule needs to be used before app bootstrap. Are you sure this should work? See https://stackoverflow.com/questions/21568075/angular-add-modules-after-angular-bootstrap


#4

You should just import module with directive, like

import './ng-tags-input';

#5

Yeaa, but then I need to inject “ngTagsInput” as dependency to any grafana module, let’s say “grafana.directives”. How do I do that?


#6

why? it’s already loaded and defined in that module


#7

sorry, I meant the grafana built in tags input