@@ -1808,10 +1808,41 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
1808
1808
}
1809
1809
}
1810
1810
1811
+ function setupControllers ( scope , isolateScope , $element , attrs , transcludeFn , elementControllers ) {
1812
+ // For directives with element transclusion the element is a comment,
1813
+ // but jQuery .data doesn't support attaching data to comment nodes as it's hard to
1814
+ // clean up (http://bugs.jquery.com/ticket/8335).
1815
+ // Instead, we save the controllers for the element in a local hash and attach to .data
1816
+ // later, once we have the actual element.
1817
+ var controllerData = ! hasElementTranscludeDirective && $element . data ( ) ;
1818
+
1819
+ for ( var directiveName in controllerDirectives ) {
1820
+ var directive = controllerDirectives [ directiveName ] ;
1821
+
1822
+ var locals = {
1823
+ $scope : directive === newIsolateScopeDirective || directive . $$isolateScope ? isolateScope : scope ,
1824
+ $element : $element ,
1825
+ $attrs : attrs ,
1826
+ $transclude : transcludeFn
1827
+ } ;
1828
+
1829
+ var controller = directive . controller ;
1830
+ if ( controller === '@' ) {
1831
+ controller = attrs [ directive . name ] ;
1832
+ }
1833
+
1834
+ var controllerInstance = $controller ( controller , locals , true , directive . controllerAs ) ;
1835
+
1836
+ elementControllers [ directive . name ] = controllerInstance ;
1837
+ if ( controllerData ) {
1838
+ controllerData [ '$' + directive . name + 'Controller' ] = controllerInstance . instance ;
1839
+ }
1840
+ }
1841
+ }
1842
+
1811
1843
1812
1844
function nodeLinkFn ( childLinkFn , scope , linkNode , $rootElement , boundTranscludeFn ) {
1813
- var i , ii , linkFn , directive , controller , isolateScope , elementControllers , transcludeFn , $element ,
1814
- attrs ;
1845
+ var i , ii , linkFn , isolateScope , elementControllers , transcludeFn , $element , attrs ;
1815
1846
1816
1847
if ( compileNode === linkNode ) {
1817
1848
attrs = templateAttrs ;
@@ -1833,37 +1864,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
1833
1864
}
1834
1865
1835
1866
if ( controllerDirectives ) {
1836
- elementControllers = { } ;
1837
-
1838
- // For directives with element transclusion the element is a comment,
1839
- // but jQuery .data doesn't support attaching data to comment nodes as it's hard to
1840
- // clean up (http://bugs.jquery.com/ticket/8335).
1841
- // Instead, we save the controllers for the element in a local hash and attach to .data
1842
- // later, once we have the actual element.
1843
- var controllerData = ! hasElementTranscludeDirective && $element . data ( ) ;
1844
-
1845
- for ( var directiveName in controllerDirectives ) {
1846
- var directive = controllerDirectives [ directiveName ] ;
1847
-
1848
- var locals = {
1849
- $scope : directive === newIsolateScopeDirective || directive . $$isolateScope ? isolateScope : scope ,
1850
- $element : $element ,
1851
- $attrs : attrs ,
1852
- $transclude : transcludeFn
1853
- } ;
1854
-
1855
- var controller = directive . controller ;
1856
- if ( controller === '@' ) {
1857
- controller = attrs [ directive . name ] ;
1858
- }
1859
-
1860
- var controllerInstance = $controller ( controller , locals , true , directive . controllerAs ) ;
1861
-
1862
- elementControllers [ directive . name ] = controllerInstance ;
1863
- if ( controllerData ) {
1864
- controllerData [ '$' + directive . name + 'Controller' ] = controllerInstance . instance ;
1865
- }
1866
- }
1867
+ setupControllers ( scope , isolateScope , $element , attrs , transcludeFn , elementControllers = { } ) ;
1867
1868
}
1868
1869
1869
1870
if ( newIsolateScopeDirective ) {
@@ -1951,8 +1952,8 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
1951
1952
}
1952
1953
1953
1954
// Initialize the controllers before linking
1954
- for ( i in elementControllers ) {
1955
- elementControllers [ i ] ( ) ;
1955
+ if ( elementControllers ) {
1956
+ invokeEach ( elementControllers ) ;
1956
1957
}
1957
1958
1958
1959
// PRELINKING
@@ -2011,6 +2012,12 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
2011
2012
}
2012
2013
}
2013
2014
2015
+ function invokeEach ( funcs ) {
2016
+ for ( var key in funcs ) {
2017
+ funcs [ key ] ( ) ;
2018
+ }
2019
+ }
2020
+
2014
2021
function markDirectivesAsIsolate ( directives ) {
2015
2022
// mark all directives as needing isolate scope.
2016
2023
for ( var j = 0 , jj = directives . length ; j < jj ; j ++ ) {
0 commit comments