This repository has been archived by the owner on Feb 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
ngTranscludeMod.js
51 lines (47 loc) · 1.75 KB
/
ngTranscludeMod.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
angular.module( 'ngTranscludeMod', [] )
.config(['$provide', function($provide) {
$provide.decorator('ngTranscludeDirective', ['$delegate', function($delegate) {
// Remove the original directive
$delegate.shift();
return $delegate;
}]);
}])
.directive( 'ngTransclude', function() {
return {
restrict: 'EAC',
link: function( $scope, $element, $attrs, controller, $transclude ) {
if (!$transclude) {
throw minErr('ngTransclude')('orphan',
'Illegal use of ngTransclude directive in the template! ' +
'No parent directive that requires a transclusion found. ' +
'Element: {0}',
startingTag($element) );
}
var iScopeType = $attrs['ngTransclude'] || 'sibling';
switch ( iScopeType ) {
case 'sibling':
$transclude( function( clone ) {
$element.empty();
$element.append( clone );
});
break;
case 'parent':
$transclude( $scope, function( clone ) {
$element.empty();
$element.append( clone );
});
break;
case 'child':
var iChildScope = $scope.$new();
$transclude( iChildScope, function( clone ) {
$element.empty();
$element.append( clone );
$element.on( '$destroy', function() {
iChildScope.$destroy();
});
});
break;
}
}
}
});