Grafana version: 6.0.0
Hi all. First of all thanks for taking the effort to read this question.
I am new to Grafana, AngularJS and Javascript in general. I am trying to implement an AngularJS Material switch demo in my Grafana plugin, without luck. The switch is simply not appearing.
After following the Clock Panel example with success, I stripped down the ctrl.ts file to a bare minimum. I got it to build with yarn and successfully print a test string in a panel i.e. my first own plugin. Now, I want to implement the AngularJS Material switch.
After spending a lot of time failing I found this blogpost. So I implemented the example and have ended up with this code:
switch_ctrl.ts
import { PanelCtrl } from 'grafana/app/plugins/sdk';
import _ from 'lodash';
import '../node_modules/angular-aria/angular-aria.js';
import '../node_modules/angular-animate/angular-animate.js';
import '../node_modules/angular-material/angular-material.js';
import '../node_modules/angular-material/angular-material-mocks.js';
import '../node_modules/angular-material/angular-material.css';
export class SwitchCtrl extends PanelCtrl {
static templateUrl = 'partials/module.html';
constructor($scope, $injector) {
super($scope, $injector);
}
}
partials/module.html
<md-switch>SWITCH</md-switch>
The AngularJS instructions show you can install the libs with npm, so that’s what I did and referenced those libs. But after adding the panel, there is no switch. Only the text.
In the element explorer, I can see the switch. Also, I can see it is being styled by “some” CSS:
However, it looks nothing like it is supposed to, if you check the rendered source code of a switch.
I can confirm however, that at the exact moment of adding the switch panel to Grafana, the supposed files are downloaded. One is a stylesheet (in some kind of blob format). And yes, when opening the preview in Chrome Developer, I see md-switch stuff. Unfortunately this forum does not allow me to upload more than two images, so I cannot show you.
So I am allowing myself to conclude that the switch_ctrl.ts is correctly referencing the HTML file and that the system understands it needs to apply AngularJS Material CSS to the md-switch HTML component.
But why is the CSS not applied properly? I have no clue. Any help will be super welcome, since this thing has been keeping me crunching my brain for some days now.