@@ -1770,10 +1770,41 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
1770
1770
}
1771
1771
}
1772
1772
1773
+ function setupControllers ( scope , isolateScope , $element , attrs , transcludeFn , elementControllers ) {
1774
+ // For directives with element transclusion the element is a comment,
1775
+ // but jQuery .data doesn't support attaching data to comment nodes as it's hard to
1776
+ // clean up (http://bugs.jquery.com/ticket/8335).
1777
+ // Instead, we save the controllers for the element in a local hash and attach to .data
1778
+ // later, once we have the actual element.
1779
+ var controllerData = ! hasElementTranscludeDirective && $element . data ( ) ;
1780
+
1781
+ for ( var directiveName in controllerDirectives ) {
1782
+ var directive = controllerDirectives [ directiveName ] ;
1783
+
1784
+ var locals = {
1785
+ $scope : directive === newIsolateScopeDirective || directive . $$isolateScope ? isolateScope : scope ,
1786
+ $element : $element ,
1787
+ $attrs : attrs ,
1788
+ $transclude : transcludeFn
1789
+ } ;
1790
+
1791
+ var controller = directive . controller ;
1792
+ if ( controller === '@' ) {
1793
+ controller = attrs [ directive . name ] ;
1794
+ }
1795
+
1796
+ var controllerInstance = $controller ( controller , locals , true , directive . controllerAs ) ;
1797
+
1798
+ elementControllers [ directive . name ] = controllerInstance ;
1799
+ if ( controllerData ) {
1800
+ controllerData [ '$' + directive . name + 'Controller' ] = controllerInstance . instance ;
1801
+ }
1802
+ }
1803
+ }
1804
+
1773
1805
1774
1806
function nodeLinkFn ( childLinkFn , scope , linkNode , $rootElement , boundTranscludeFn ) {
1775
- var i , ii , linkFn , directive , controller , isolateScope , elementControllers , transcludeFn , $element ,
1776
- attrs ;
1807
+ var i , ii , linkFn , isolateScope , elementControllers , transcludeFn , $element , attrs ;
1777
1808
1778
1809
if ( compileNode === linkNode ) {
1779
1810
attrs = templateAttrs ;
@@ -1789,37 +1820,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
1789
1820
1790
1821
transcludeFn = boundTranscludeFn && controllersBoundTransclude ;
1791
1822
if ( controllerDirectives ) {
1792
- elementControllers = { } ;
1793
-
1794
- // For directives with element transclusion the element is a comment,
1795
- // but jQuery .data doesn't support attaching data to comment nodes as it's hard to
1796
- // clean up (http://bugs.jquery.com/ticket/8335).
1797
- // Instead, we save the controllers for the element in a local hash and attach to .data
1798
- // later, once we have the actual element.
1799
- var controllerData = ! hasElementTranscludeDirective && $element . data ( ) ;
1800
-
1801
- for ( var directiveName in controllerDirectives ) {
1802
- var directive = controllerDirectives [ directiveName ] ;
1803
-
1804
- var locals = {
1805
- $scope : directive === newIsolateScopeDirective || directive . $$isolateScope ? isolateScope : scope ,
1806
- $element : $element ,
1807
- $attrs : attrs ,
1808
- $transclude : transcludeFn
1809
- } ;
1810
-
1811
- var controller = directive . controller ;
1812
- if ( controller === '@' ) {
1813
- controller = attrs [ directive . name ] ;
1814
- }
1815
-
1816
- var controllerInstance = $controller ( controller , locals , true , directive . controllerAs ) ;
1817
-
1818
- elementControllers [ directive . name ] = controllerInstance ;
1819
- if ( controllerData ) {
1820
- controllerData [ '$' + directive . name + 'Controller' ] = controllerInstance . instance ;
1821
- }
1822
- }
1823
+ setupControllers ( scope , isolateScope , $element , attrs , transcludeFn , elementControllers = { } ) ;
1823
1824
}
1824
1825
1825
1826
if ( newIsolateScopeDirective ) {
@@ -1907,8 +1908,8 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
1907
1908
}
1908
1909
1909
1910
// Initialize the controllers before linking
1910
- for ( i in elementControllers ) {
1911
- elementControllers [ i ] ( ) ;
1911
+ if ( elementControllers ) {
1912
+ invokeEach ( elementControllers ) ;
1912
1913
}
1913
1914
1914
1915
// PRELINKING
@@ -1967,6 +1968,12 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
1967
1968
}
1968
1969
}
1969
1970
1971
+ function invokeEach ( funcs ) {
1972
+ for ( var key in funcs ) {
1973
+ funcs [ key ] ( ) ;
1974
+ }
1975
+ }
1976
+
1970
1977
function markDirectivesAsIsolate ( directives ) {
1971
1978
// mark all directives as needing isolate scope.
1972
1979
for ( var j = 0 , jj = directives . length ; j < jj ; j ++ ) {
0 commit comments