@@ -1826,10 +1826,41 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
1826
1826
}
1827
1827
}
1828
1828
1829
+ function setupControllers ( scope , isolateScope , $element , attrs , transcludeFn , elementControllers ) {
1830
+ // For directives with element transclusion the element is a comment,
1831
+ // but jQuery .data doesn't support attaching data to comment nodes as it's hard to
1832
+ // clean up (http://bugs.jquery.com/ticket/8335).
1833
+ // Instead, we save the controllers for the element in a local hash and attach to .data
1834
+ // later, once we have the actual element.
1835
+ var controllerData = ! hasElementTranscludeDirective && $element . data ( ) ;
1836
+
1837
+ for ( var directiveName in controllerDirectives ) {
1838
+ var directive = controllerDirectives [ directiveName ] ;
1839
+
1840
+ var locals = {
1841
+ $scope : directive === newIsolateScopeDirective || directive . $$isolateScope ? isolateScope : scope ,
1842
+ $element : $element ,
1843
+ $attrs : attrs ,
1844
+ $transclude : transcludeFn
1845
+ } ;
1846
+
1847
+ var controller = directive . controller ;
1848
+ if ( controller === '@' ) {
1849
+ controller = attrs [ directive . name ] ;
1850
+ }
1851
+
1852
+ var controllerInstance = $controller ( controller , locals , true , directive . controllerAs ) ;
1853
+
1854
+ elementControllers [ directive . name ] = controllerInstance ;
1855
+ if ( controllerData ) {
1856
+ controllerData [ '$' + directive . name + 'Controller' ] = controllerInstance . instance ;
1857
+ }
1858
+ }
1859
+ }
1860
+
1829
1861
1830
1862
function nodeLinkFn ( childLinkFn , scope , linkNode , $rootElement , boundTranscludeFn ) {
1831
- var i , ii , linkFn , directive , controller , isolateScope , elementControllers , transcludeFn , $element ,
1832
- attrs ;
1863
+ var i , ii , linkFn , isolateScope , elementControllers , transcludeFn , $element , attrs ;
1833
1864
1834
1865
if ( compileNode === linkNode ) {
1835
1866
attrs = templateAttrs ;
@@ -1851,37 +1882,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
1851
1882
}
1852
1883
1853
1884
if ( controllerDirectives ) {
1854
- elementControllers = { } ;
1855
-
1856
- // For directives with element transclusion the element is a comment,
1857
- // but jQuery .data doesn't support attaching data to comment nodes as it's hard to
1858
- // clean up (http://bugs.jquery.com/ticket/8335).
1859
- // Instead, we save the controllers for the element in a local hash and attach to .data
1860
- // later, once we have the actual element.
1861
- var controllerData = ! hasElementTranscludeDirective && $element . data ( ) ;
1862
-
1863
- for ( var directiveName in controllerDirectives ) {
1864
- var directive = controllerDirectives [ directiveName ] ;
1865
-
1866
- var locals = {
1867
- $scope : directive === newIsolateScopeDirective || directive . $$isolateScope ? isolateScope : scope ,
1868
- $element : $element ,
1869
- $attrs : attrs ,
1870
- $transclude : transcludeFn
1871
- } ;
1872
-
1873
- var controller = directive . controller ;
1874
- if ( controller === '@' ) {
1875
- controller = attrs [ directive . name ] ;
1876
- }
1877
-
1878
- var controllerInstance = $controller ( controller , locals , true , directive . controllerAs ) ;
1879
-
1880
- elementControllers [ directive . name ] = controllerInstance ;
1881
- if ( controllerData ) {
1882
- controllerData [ '$' + directive . name + 'Controller' ] = controllerInstance . instance ;
1883
- }
1884
- }
1885
+ setupControllers ( scope , isolateScope , $element , attrs , transcludeFn , elementControllers = { } ) ;
1885
1886
}
1886
1887
1887
1888
if ( newIsolateScopeDirective ) {
@@ -1969,8 +1970,8 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
1969
1970
}
1970
1971
1971
1972
// Initialize the controllers before linking
1972
- for ( i in elementControllers ) {
1973
- elementControllers [ i ] ( ) ;
1973
+ if ( elementControllers ) {
1974
+ invokeEach ( elementControllers ) ;
1974
1975
}
1975
1976
1976
1977
// PRELINKING
@@ -2029,6 +2030,12 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
2029
2030
}
2030
2031
}
2031
2032
2033
+ function invokeEach ( funcs ) {
2034
+ for ( var key in funcs ) {
2035
+ funcs [ key ] ( ) ;
2036
+ }
2037
+ }
2038
+
2032
2039
function markDirectivesAsIsolate ( directives ) {
2033
2040
// mark all directives as needing isolate scope.
2034
2041
for ( var j = 0 , jj = directives . length ; j < jj ; j ++ ) {
0 commit comments