@@ -11,9 +11,11 @@ describe('uiScroll', function () {
1111 } ) ;
1212 myApp . controller ( 'MyInnerController' , function ( $scope ) {
1313 $scope . name = 'MyInnerController' ;
14+ $scope . container = { } ;
1415 } ) ;
1516 myApp . controller ( 'MyBottomController' , function ( $scope ) {
1617 $scope . name = 'MyBottomController' ;
18+ $scope . container = { } ;
1719 } ) ;
1820
1921 beforeEach ( module ( 'myApp' ) ) ;
@@ -22,8 +24,11 @@ describe('uiScroll', function () {
2224 return function ( ) {
2325 var directive = {
2426 restrict : 'E' ,
25- controller : function ( ) {
27+ scope : true ,
28+ controller : function ( $scope ) {
2629 this . show = true ;
30+ this . container = { } ;
31+ $scope . container = { } ;
2732 }
2833 } ;
2934 if ( options . ctrlAs ) {
@@ -34,7 +39,7 @@ describe('uiScroll', function () {
3439 } ;
3540 } ;
3641
37- var executeTest = function ( template , ctrlSelector , scopeContainer ) {
42+ var executeTest = function ( template , scopeSelector , scopeContainer ) {
3843 inject ( function ( $rootScope , $compile , $timeout ) {
3944 // build and render
4045 var templateElement = angular . element ( template ) ;
@@ -46,9 +51,14 @@ describe('uiScroll', function () {
4651
4752 // find adapter element and scope container
4853 var adapterContainer ;
49- if ( ctrlSelector ) {
54+ if ( scopeSelector ) {
5055 var adapterElement ;
51- adapterElement = templateElement . find ( '[ng-controller="' + ctrlSelector + '"]' ) ;
56+ if ( typeof scopeSelector === 'string' ) {
57+ adapterElement = templateElement . find ( '[ng-controller="' + scopeSelector + '"]' ) ;
58+ }
59+ else { //number
60+ adapterElement = templateElement . find ( 'my-dir' + scopeSelector ) ;
61+ }
5262 adapterContainer = adapterElement . scope ( ) ;
5363 }
5464 else {
@@ -207,7 +217,7 @@ describe('uiScroll', function () {
207217 '</div>' +
208218 '</div>' +
209219'</div>' ;
210- executeTest ( template , 'MyBottomController' , 'ctrl' ) ;
220+ executeTest ( template , 1 , 'ctrl' ) ;
211221 } ) ;
212222
213223 it ( 'should work for custom directive with "Controller As" syntax (no viewport)' , function ( ) {
@@ -228,7 +238,7 @@ describe('uiScroll', function () {
228238 '</div>' +
229239 '</div>' +
230240'</div>' ;
231- executeTest ( template , 'MyBottomController' , 'ctrl' ) ;
241+ executeTest ( template , 2 , 'ctrl' ) ;
232242 } ) ;
233243
234244 it ( 'should work for custom directive with the adapter defined on some external controller' , function ( ) {
@@ -251,6 +261,27 @@ describe('uiScroll', function () {
251261'</div>' ;
252262 executeTest ( template , 'MyInnerController as ctrl' , 'ctrl' ) ;
253263 } ) ;
264+
265+ it ( 'should work with "Controller As" and ingnore intermediate containers which are not controllers' , function ( ) {
266+ myApp . directive ( 'myDir4' , setDirective ( {
267+ ctrlAs : 'ctrl2' ,
268+ template :
269+ '<div style="height:200px" ng-if="ctrl2.show">' +
270+ '<div ui-scroll="item in myMultipageDatasource" adapter="container.adapter">' +
271+ '{{$index}}: {{item}}' +
272+ '</div>' +
273+ '</div>'
274+ } ) ) ;
275+ var template =
276+ '<div ng-controller="MyTopController">' +
277+ '<div ng-controller="MyInnerController as container" ng-if="name">' +
278+ '<div ng-controller="MyBottomController" ng-if="name">' +
279+ '<my-dir4></my-dir4>' +
280+ '</div>' +
281+ '</div>' +
282+ '</div>' ; // here Directive and MyBottomController have a container object
283+ executeTest ( template , 'MyInnerController as container' , 'container' ) ;
284+ } ) ;
254285 } ) ;
255286
256287} ) ;
0 commit comments