@@ -417,6 +417,7 @@ angular.module('ui.scroll', [])
417
417
}
418
418
419
419
function Adapter ( $attr , viewport , buffer , adjustBuffer , element ) {
420
+ const hasViewport = ! ! viewport . scope ( ) ;
420
421
const viewportScope = viewport . scope ( ) || $rootScope ;
421
422
let disabled = false ;
422
423
let self = this ;
@@ -514,31 +515,48 @@ angular.module('ui.scroll', [])
514
515
let target = match [ 1 ] ;
515
516
let onControllerName = match [ 2 ] ;
516
517
517
- let parseControllers = ( controllerName , as = false ) => {
518
+ // ng-controller attr based DOM parsing
519
+ let parseNgCtrlAttrs = ( controllerName , as = false ) => {
518
520
let candidate = element ;
519
521
while ( candidate . length ) {
522
+ let candidateScope = candidate . scope ( ) ;
520
523
let candidateName = ( candidate . attr ( 'ng-controller' ) || '' ) . match ( / ( \w (?: \w | \d ) * ) (?: \s + a s \s + ( \w (?: \w | \d ) * ) ) ? / ) ;
521
524
if ( candidateName && candidateName [ as ? 2 : 1 ] === controllerName ) {
522
- scope = candidate . scope ( ) ;
523
- break ;
525
+ scope = candidateScope ;
526
+ return true ;
524
527
}
525
528
candidate = candidate . parent ( ) ;
526
529
}
527
530
} ;
528
531
529
- if ( onControllerName ) { // 'on' syntax parsing
532
+ // scope based DOM pasrsing
533
+ let parseScopes = ( controllerName ) => {
534
+ let candidate = element ;
535
+ while ( candidate . length ) {
536
+ let candidateScope = candidate . scope ( ) ;
537
+ if ( candidateScope && candidateScope . hasOwnProperty ( controllerName ) && candidateScope [ controllerName ] . constructor . name === 'controller' ) {
538
+ scope = candidateScope ;
539
+ return true ;
540
+ }
541
+ candidate = candidate . parent ( ) ;
542
+ }
543
+ } ;
544
+
545
+ if ( onControllerName ) { // 'on' syntax DOM parsing (adapter="adapter on ctrl")
530
546
scope = null ;
531
- parseControllers ( onControllerName ) ;
547
+ parseNgCtrlAttrs ( onControllerName ) ;
532
548
if ( ! scope ) {
533
549
throw new Error ( 'Failed to locate target controller \'' + onControllerName + '\' to inject \'' + target + '\'' ) ;
534
550
}
535
551
}
536
- else { // try to parse with 'Controller As' syntax
552
+ else { // try to parse DOM with 'Controller As' syntax (adapter="ctrl.adapter")
537
553
let controllerAsName ;
538
554
let dotIndex = target . indexOf ( '.' ) ;
539
555
if ( dotIndex > 0 ) {
540
556
controllerAsName = target . substr ( 0 , dotIndex ) ;
541
- parseControllers ( controllerAsName , true ) ;
557
+ if ( ! parseNgCtrlAttrs ( controllerAsName , true ) && ! hasViewport ) {
558
+ parseScopes ( controllerAsName ) ; // the case of custom Directive/Component
559
+ }
542
560
}
543
561
}
544
562
0 commit comments