@@ -103,6 +103,7 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
103103 'class="' + startSym + 'class' + endSym + '" ' +
104104 'animation="animation" ' +
105105 'is-open="isOpen"' +
106+ 'origin-scope="origScope" ' +
106107 '>' +
107108 '</div>' ;
108109
@@ -111,7 +112,7 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
111112 compile : function ( tElem , tAttrs ) {
112113 var tooltipLinker = $compile ( template ) ;
113114
114- return function link ( scope , element , attrs ) {
115+ return function link ( scope , element , attrs , tooltipCtrl ) {
115116 var tooltip ;
116117 var tooltipLinkedScope ;
117118 var transitionTimeout ;
@@ -132,6 +133,9 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
132133 tooltip . css ( ttPosition ) ;
133134 } ;
134135
136+ // Set up the correct scope to allow transclusion later
137+ ttScope . origScope = scope ;
138+
135139 // By default, the tooltip is not open.
136140 // TODO add ability to start tooltip opened
137141 ttScope . isOpen = false ;
@@ -197,7 +201,7 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
197201
198202 // And show the tooltip.
199203 ttScope . isOpen = true ;
200- ttScope . $digest ( ) ; // digest required as $apply is not called
204+ ttScope . $apply ( ) ; // digest required as $apply is not called
201205
202206 // Return positioning function as promise callback for correct
203207 // positioning after draw.
@@ -349,6 +353,74 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
349353 } ] ;
350354} )
351355
356+ // This is mostly ngInclude code but with a custom scope
357+ . directive ( 'tooltipTemplateTransclude' , [
358+ '$animate' , '$sce' , '$compile' , '$templateRequest' ,
359+ function ( $animate , $sce , $compile , $templateRequest ) {
360+ return {
361+ link : function ( scope , elem , attrs ) {
362+ var origScope = scope . $eval ( attrs . tooltipTemplateTranscludeScope ) ;
363+
364+ var changeCounter = 0 ,
365+ currentScope ,
366+ previousElement ,
367+ currentElement ;
368+
369+ var cleanupLastIncludeContent = function ( ) {
370+ if ( previousElement ) {
371+ previousElement . remove ( ) ;
372+ previousElement = null ;
373+ }
374+ if ( currentScope ) {
375+ currentScope . $destroy ( ) ;
376+ currentScope = null ;
377+ }
378+ if ( currentElement ) {
379+ $animate . leave ( currentElement ) . then ( function ( ) {
380+ previousElement = null ;
381+ } ) ;
382+ previousElement = currentElement ;
383+ currentElement = null ;
384+ }
385+ } ;
386+
387+ scope . $watch ( $sce . parseAsResourceUrl ( attrs . tooltipTemplateTransclude ) , function ( src ) {
388+ var thisChangeId = ++ changeCounter ;
389+
390+ if ( src ) {
391+ //set the 2nd param to true to ignore the template request error so that the inner
392+ //contents and scope can be cleaned up.
393+ $templateRequest ( src , true ) . then ( function ( response ) {
394+ if ( thisChangeId !== changeCounter ) { return ; }
395+ var newScope = origScope . $new ( ) ;
396+ var template = response ;
397+
398+ var clone = $compile ( template ) ( newScope , function ( clone ) {
399+ cleanupLastIncludeContent ( ) ;
400+ $animate . enter ( clone , elem ) ;
401+ } ) ;
402+
403+ currentScope = newScope ;
404+ currentElement = clone ;
405+
406+ currentScope . $emit ( '$includeContentLoaded' , src ) ;
407+ } , function ( ) {
408+ if ( thisChangeId === changeCounter ) {
409+ cleanupLastIncludeContent ( ) ;
410+ scope . $emit ( '$includeContentError' , src ) ;
411+ }
412+ } ) ;
413+ scope . $emit ( '$includeContentRequested' , src ) ;
414+ } else {
415+ cleanupLastIncludeContent ( ) ;
416+ }
417+ } ) ;
418+
419+ scope . $on ( '$destroy' , cleanupLastIncludeContent ) ;
420+ }
421+ } ;
422+ } ] )
423+
352424. directive ( 'tooltipPopup' , function ( ) {
353425 return {
354426 restrict : 'EA' ,
0 commit comments