mirror of
https://github.com/grafana/grafana.git
synced 2025-01-09 15:43:23 -06:00
3a7623753b
* build(webpack): replace babel-loader with esbuild-loader * build(webpack): add esbuild minifier to production builds * Wip * Removed ngInject and replaced with manual inject params * chore: bump esbuild to 0.15.13 * Fixed angular issues * build(frontend): update esbuild to 0.16.16 * chore(webpack): support browserslist for esbuild * build(esbuild): unify versions of esbuild to 0.16.17 and esbuild-loader to 2.21.0 Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
58 lines
1.5 KiB
TypeScript
58 lines
1.5 KiB
TypeScript
import angular from 'angular';
|
|
|
|
import coreModule from '../core_module';
|
|
|
|
class DynamicDirectiveSrv {
|
|
static $inject = ['$compile'];
|
|
|
|
constructor(private $compile: angular.ICompileService) {}
|
|
|
|
addDirective(element: any, name: string, scope: any) {
|
|
const child = angular.element(document.createElement(name));
|
|
this.$compile(child)(scope);
|
|
|
|
element.empty();
|
|
element.append(child);
|
|
}
|
|
|
|
link(scope: any, elem: JQLite, attrs: any, options: any) {
|
|
const directiveInfo = options.directive(scope);
|
|
if (!directiveInfo || !directiveInfo.fn) {
|
|
elem.empty();
|
|
return;
|
|
}
|
|
|
|
if (!directiveInfo.fn.registered) {
|
|
coreModule.directive(attrs.$normalize(directiveInfo.name), directiveInfo.fn);
|
|
directiveInfo.fn.registered = true;
|
|
}
|
|
|
|
this.addDirective(elem, directiveInfo.name, scope);
|
|
}
|
|
|
|
create(options: any) {
|
|
const directiveDef = {
|
|
restrict: 'E',
|
|
scope: options.scope,
|
|
link: (scope: any, elem: JQLite, attrs: any) => {
|
|
if (options.watchPath) {
|
|
let childScope: any = null;
|
|
scope.$watch(options.watchPath, () => {
|
|
if (childScope) {
|
|
childScope.$destroy();
|
|
}
|
|
childScope = scope.$new();
|
|
this.link(childScope, elem, attrs, options);
|
|
});
|
|
} else {
|
|
this.link(scope, elem, attrs, options);
|
|
}
|
|
},
|
|
};
|
|
|
|
return directiveDef;
|
|
}
|
|
}
|
|
|
|
coreModule.service('dynamicDirectiveSrv', DynamicDirectiveSrv);
|