mirror of
https://github.com/nasa/openmct.git
synced 2025-05-04 17:52:58 +00:00
[Representation] Use transclusion for mct-include
...to add/remove conditionally depending on the existence of certain templates. Note that this currently breaks mct-include due to an incompatibility between element transclusion and directive templates; see https://github.com/angular/angular.js/issues/3368.
This commit is contained in:
parent
757cb0f015
commit
942f617bd8
@ -69,19 +69,39 @@ define(
|
|||||||
templateMap[key] = templateMap[key] || path;
|
templateMap[key] = templateMap[key] || path;
|
||||||
});
|
});
|
||||||
|
|
||||||
function controller($scope) {
|
function link($scope, element, attrs, ctrl, transclude) {
|
||||||
|
var originalElement = element,
|
||||||
|
activeElement = element;
|
||||||
|
|
||||||
$scope.$watch('key', function (key) {
|
$scope.$watch('key', function (key) {
|
||||||
// Pass the template URL to ng-include via scope.
|
if (templateMap[key]) {
|
||||||
$scope.inclusion = templateMap[$scope.key];
|
// Pass the template URL to ng-include via scope.
|
||||||
|
$scope.inclusion = templateMap[$scope.key];
|
||||||
|
// ...and add the template to the DOM.
|
||||||
|
transclude(function (clone) {
|
||||||
|
activeElement.replaceWith(clone);
|
||||||
|
activeElement = clone;
|
||||||
|
});
|
||||||
|
} else if (activeElement !== originalElement) {
|
||||||
|
// If the key is unknown, remove it from DOM entirely.
|
||||||
|
activeElement.replaceWith(originalElement);
|
||||||
|
activeElement = originalElement;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
transclude: 'element',
|
||||||
|
|
||||||
|
priority: 601,
|
||||||
|
|
||||||
|
terminal: true,
|
||||||
|
|
||||||
// Only show at the element level
|
// Only show at the element level
|
||||||
restrict: "E",
|
restrict: "E",
|
||||||
|
|
||||||
// Use the included controller to populate scope
|
// Use the included controller to populate scope
|
||||||
controller: controller,
|
link: link,
|
||||||
|
|
||||||
// Use ng-include as a template; "inclusion" will be the real
|
// Use ng-include as a template; "inclusion" will be the real
|
||||||
// template path
|
// template path
|
||||||
|
Loading…
x
Reference in New Issue
Block a user