|
@@ -6,7 +6,7 @@ import coreModule from '../core_module';
|
|
|
class DynamicDirectiveSrv {
|
|
class DynamicDirectiveSrv {
|
|
|
|
|
|
|
|
/** @ngInject */
|
|
/** @ngInject */
|
|
|
- constructor(private $compile, private $parse) {}
|
|
|
|
|
|
|
+ constructor(private $compile, private $parse, private $rootScope) {}
|
|
|
|
|
|
|
|
addDirective(element, name, scope) {
|
|
addDirective(element, name, scope) {
|
|
|
var child = angular.element(document.createElement(name));
|
|
var child = angular.element(document.createElement(name));
|
|
@@ -16,25 +16,35 @@ class DynamicDirectiveSrv {
|
|
|
element.append(child);
|
|
element.append(child);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ link(scope, elem, attrs, options) {
|
|
|
|
|
+ options.directive(scope).then(directiveInfo => {
|
|
|
|
|
+ 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);
|
|
|
|
|
+ }).catch(err => {
|
|
|
|
|
+ console.log('Plugin load:', err);
|
|
|
|
|
+ this.$rootScope.appEvent('alert-error', ['Plugin error', err.toString()]);
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
create(options) {
|
|
create(options) {
|
|
|
let directiveDef = {
|
|
let directiveDef = {
|
|
|
restrict: 'E',
|
|
restrict: 'E',
|
|
|
scope: options.scope,
|
|
scope: options.scope,
|
|
|
link: (scope, elem, attrs) => {
|
|
link: (scope, elem, attrs) => {
|
|
|
- options.directive(scope).then(directiveInfo => {
|
|
|
|
|
- if (!directiveInfo || !directiveInfo.fn) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (!directiveInfo.fn.registered) {
|
|
|
|
|
- coreModule.directive(attrs.$normalize(directiveInfo.name), directiveInfo.fn);
|
|
|
|
|
- directiveInfo.fn.registered = true;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- this.addDirective(elem, directiveInfo.name, scope);
|
|
|
|
|
- }).catch(function(err) {
|
|
|
|
|
- console.log('Dynamic directive load error: ', err);
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ if (options.watch) {
|
|
|
|
|
+ scope.$watch(options.watch,() => this.link(scope, elem, attrs, options));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ this.link(scope, elem, attrs, options);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
|
|
|