@@ -1840,49 +1840,42 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
1840
1840
1841
1841
1842
1842
function getControllers ( directiveName , require , $element , elementControllers ) {
1843
- var value , retrievalMethod = 'data' , optional = false ;
1844
- var $searchElement = $element ;
1845
- var match ;
1846
- if ( isString ( require ) ) {
1847
- match = require . match ( REQUIRE_PREFIX_REGEXP ) ;
1848
- require = require . substring ( match [ 0 ] . length ) ;
1843
+ var value ;
1849
1844
1850
- if ( match [ 3 ] ) {
1851
- if ( match [ 1 ] ) match [ 3 ] = null ;
1852
- else match [ 1 ] = match [ 3 ] ;
1853
- }
1854
- if ( match [ 1 ] === '^' ) {
1855
- retrievalMethod = 'inheritedData' ;
1856
- } else if ( match [ 1 ] === '^^' ) {
1857
- retrievalMethod = 'inheritedData' ;
1858
- $searchElement = $element . parent ( ) ;
1859
- }
1860
- if ( match [ 2 ] === '?' ) {
1861
- optional = true ;
1845
+ if ( isString ( require ) ) {
1846
+ var match = require . match ( REQUIRE_PREFIX_REGEXP ) ;
1847
+ var name = require . substring ( match [ 0 ] . length ) ;
1848
+ var inheritType = match [ 1 ] || match [ 3 ] ;
1849
+ var optional = match [ 2 ] === '?' ;
1850
+
1851
+ //If only parents then start at the parent element
1852
+ if ( inheritType === '^^' ) {
1853
+ $element = $element . parent ( ) ;
1854
+ //Otherwise attempt getting the controller from elementControllers in case
1855
+ //the element is transcluded (and has no data) and to avoid .data if possible
1856
+ } else {
1857
+ value = elementControllers && elementControllers [ name ] ;
1858
+ value = value && value . instance ;
1862
1859
}
1863
1860
1864
- value = null ;
1865
-
1866
- if ( elementControllers && retrievalMethod === 'data' ) {
1867
- if ( value = elementControllers [ require ] ) {
1868
- value = value . instance ;
1869
- }
1861
+ if ( ! value ) {
1862
+ var dataName = '$' + name + 'Controller' ;
1863
+ value = inheritType ? $element . inheritedData ( dataName ) : $element . data ( dataName ) ;
1870
1864
}
1871
- value = value || $searchElement [ retrievalMethod ] ( '$' + require + 'Controller' ) ;
1872
1865
1873
1866
if ( ! value && ! optional ) {
1874
1867
throw $compileMinErr ( 'ctreq' ,
1875
1868
"Controller '{0}', required by directive '{1}', can't be found!" ,
1876
- require , directiveName ) ;
1869
+ name , directiveName ) ;
1877
1870
}
1878
- return value || null ;
1879
1871
} else if ( isArray ( require ) ) {
1880
1872
value = [ ] ;
1881
- forEach ( require , function ( require ) {
1882
- value . push ( getControllers ( directiveName , require , $element , elementControllers ) ) ;
1883
- } ) ;
1873
+ for ( var i = 0 , ii = require . length ; i < ii ; i ++ ) {
1874
+ value [ i ] = getControllers ( directiveName , require [ i ] , $element , elementControllers ) ;
1875
+ }
1884
1876
}
1885
- return value ;
1877
+
1878
+ return value || null ;
1886
1879
}
1887
1880
1888
1881
0 commit comments