Importing new angular modules/dependencies

Hello everyone! I’m currently developing a custom plugin for grafana. I’d like to leverage angular animations. However, the current frontend code only lists ngRoute and ngSanitize among other ngModuleDependencies. Is it possible for me to somehow add ngAnimate to the list of dependencies? Or maybe to integrate my own angular module to the existing grafana module? And, more importantly, is it possible to do that from within my plugin, without forking grafana and adding those dependencies to the source code? Thanks in advance!

This is a bit tricky and I haven’t tried it myself and there is no example of this anymore.

  1. You are going to need to download ngAnimate and include it in the source of your plugin and import it into your module file.
  2. Create your own plugin module that uses ngAnimate: angular.module('myplugin', ['ngAnimate']);
  3. Import grafana app (app/app) and load your module with the useModule function: https://github.com/grafana/grafana/blob/master/public/app/app.ts#L97

Here is an old, out-of-date (and deleted) example:

Hi Daniel, thank you for your response! I’ve been playing with this useModule(module) api for a few days. Unfortunately I didn’t manage to get it to work. While it looks like it’s there to give me as a developer the possibility to add my own modules to the existing grafana module, in practice there’s one problem. My plugin’s code (module.js, panel controllers etc) is loaded by the browser after the file boot.[hash code].js. This boot.js file bootstraps the angular application and it doesn’t include my plugin’s code. So this useModule(module) call is pretty much useless - by the time this code gets executed, the application will have already been bootstrapped.

That’s why my question remains - am I supposed to be able to integrate my own modules to the application? Or there is something I am missing?

2 Likes

This is over a year old but, @serguntchik, did you ever determine how this is done?

Hey jcluff, we haven’t found any solution to do that from within the plugin. What we did instead is we simply forked grafana and made the necessary updates to the fork.

Okay. Thanks for the response!!