@@ -11,9 +11,11 @@ describe('uiScroll', function () {
11
11
} ) ;
12
12
myApp . controller ( 'MyInnerController' , function ( $scope ) {
13
13
$scope . name = 'MyInnerController' ;
14
+ $scope . container = { } ;
14
15
} ) ;
15
16
myApp . controller ( 'MyBottomController' , function ( $scope ) {
16
17
$scope . name = 'MyBottomController' ;
18
+ $scope . container = { } ;
17
19
} ) ;
18
20
19
21
beforeEach ( module ( 'myApp' ) ) ;
@@ -22,8 +24,11 @@ describe('uiScroll', function () {
22
24
return function ( ) {
23
25
var directive = {
24
26
restrict : 'E' ,
25
- controller : function ( ) {
27
+ scope : true ,
28
+ controller : function ( $scope ) {
26
29
this . show = true ;
30
+ this . container = { } ;
31
+ $scope . container = { } ;
27
32
}
28
33
} ;
29
34
if ( options . ctrlAs ) {
@@ -34,7 +39,7 @@ describe('uiScroll', function () {
34
39
} ;
35
40
} ;
36
41
37
- var executeTest = function ( template , ctrlSelector , scopeContainer ) {
42
+ var executeTest = function ( template , scopeSelector , scopeContainer ) {
38
43
inject ( function ( $rootScope , $compile , $timeout ) {
39
44
// build and render
40
45
var templateElement = angular . element ( template ) ;
@@ -46,9 +51,14 @@ describe('uiScroll', function () {
46
51
47
52
// find adapter element and scope container
48
53
var adapterContainer ;
49
- if ( ctrlSelector ) {
54
+ if ( scopeSelector ) {
50
55
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
+ }
52
62
adapterContainer = adapterElement . scope ( ) ;
53
63
}
54
64
else {
@@ -207,7 +217,7 @@ describe('uiScroll', function () {
207
217
'</div>' +
208
218
'</div>' +
209
219
'</div>' ;
210
- executeTest ( template , 'MyBottomController' , 'ctrl' ) ;
220
+ executeTest ( template , 1 , 'ctrl' ) ;
211
221
} ) ;
212
222
213
223
it ( 'should work for custom directive with "Controller As" syntax (no viewport)' , function ( ) {
@@ -228,7 +238,7 @@ describe('uiScroll', function () {
228
238
'</div>' +
229
239
'</div>' +
230
240
'</div>' ;
231
- executeTest ( template , 'MyBottomController' , 'ctrl' ) ;
241
+ executeTest ( template , 2 , 'ctrl' ) ;
232
242
} ) ;
233
243
234
244
it ( 'should work for custom directive with the adapter defined on some external controller' , function ( ) {
@@ -251,6 +261,27 @@ describe('uiScroll', function () {
251
261
'</div>' ;
252
262
executeTest ( template , 'MyInnerController as ctrl' , 'ctrl' ) ;
253
263
} ) ;
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
+ } ) ;
254
285
} ) ;
255
286
256
287
} ) ;
0 commit comments