You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.1 KiB
JavaScript
39 lines
1.1 KiB
JavaScript
/*
|
|
* Defines the ui-if tag. This removes/adds an element from the dom depending on a condition
|
|
* Originally created by @tigbro, for the @jquery-mobile-angular-adapter
|
|
* https://github.com/tigbro/jquery-mobile-angular-adapter
|
|
*/
|
|
angular.module('ui.directives').directive('uiIf', [function () {
|
|
return {
|
|
transclude: 'element',
|
|
priority: 1000,
|
|
terminal: true,
|
|
restrict: 'A',
|
|
compile: function (element, attr, transclude) {
|
|
return function (scope, element, attr) {
|
|
|
|
var childElement;
|
|
var childScope;
|
|
|
|
scope.$watch(attr['uiIf'], function (newValue) {
|
|
if (childElement) {
|
|
childElement.remove();
|
|
childElement = undefined;
|
|
}
|
|
if (childScope) {
|
|
childScope.$destroy();
|
|
childScope = undefined;
|
|
}
|
|
|
|
if (newValue) {
|
|
childScope = scope.$new();
|
|
transclude(childScope, function (clone) {
|
|
childElement = clone;
|
|
element.after(clone);
|
|
});
|
|
}
|
|
});
|
|
};
|
|
}
|
|
};
|
|
}]); |