mirror of
https://github.com/nasa/openmct.git
synced 2024-12-20 21:53:08 +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;
|
||||
});
|
||||
|
||||
function controller($scope) {
|
||||
function link($scope, element, attrs, ctrl, transclude) {
|
||||
var originalElement = element,
|
||||
activeElement = element;
|
||||
|
||||
$scope.$watch('key', function (key) {
|
||||
// Pass the template URL to ng-include via scope.
|
||||
$scope.inclusion = templateMap[$scope.key];
|
||||
if (templateMap[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 {
|
||||
transclude: 'element',
|
||||
|
||||
priority: 601,
|
||||
|
||||
terminal: true,
|
||||
|
||||
// Only show at the element level
|
||||
restrict: "E",
|
||||
|
||||
// Use the included controller to populate scope
|
||||
controller: controller,
|
||||
link: link,
|
||||
|
||||
// Use ng-include as a template; "inclusion" will be the real
|
||||
// template path
|
||||
|
Loading…
Reference in New Issue
Block a user