@@ -85,4 +85,59 @@ describe('ngController', function() {
85
85
$rootScope . $digest ( ) ;
86
86
expect ( element . text ( ) ) . toBe ( 'Vojta' ) ;
87
87
} ) ) ;
88
+
89
+
90
+ it ( 'should work with ngInclude on the same element' , inject ( function ( $compile , $rootScope , $httpBackend ) {
91
+ $rootScope . GreeterController = function ( $scope ) {
92
+ $scope . name = 'Vojta' ;
93
+ } ;
94
+
95
+ element = $compile ( '<div><div ng-controller="GreeterController" ng-include="\'url\'"></div></div>' ) ( $rootScope ) ;
96
+ $httpBackend . expect ( 'GET' , 'url' ) . respond ( '{{name}}' ) ;
97
+ $rootScope . $digest ( ) ;
98
+ $httpBackend . flush ( ) ;
99
+ expect ( element . text ( ) ) . toEqual ( 'Vojta' ) ;
100
+ } ) ) ;
101
+
102
+
103
+ it ( 'should only instantiate the controller once with ngInclude on the same element' ,
104
+ inject ( function ( $compile , $rootScope , $httpBackend ) {
105
+
106
+ var count = 0 ;
107
+
108
+ $rootScope . CountController = function ( $scope ) {
109
+ count += 1 ;
110
+ } ;
111
+
112
+ element = $compile ( '<div><div ng-controller="CountController" ng-include="url"></div></div>' ) ( $rootScope ) ;
113
+
114
+ $httpBackend . expect ( 'GET' , 'first' ) . respond ( 'first' ) ;
115
+ $rootScope . url = 'first' ;
116
+ $rootScope . $digest ( ) ;
117
+ $httpBackend . flush ( ) ;
118
+
119
+ $httpBackend . expect ( 'GET' , 'second' ) . respond ( 'second' ) ;
120
+ $rootScope . url = 'second' ;
121
+ $rootScope . $digest ( ) ;
122
+ $httpBackend . flush ( ) ;
123
+
124
+ expect ( count ) . toBe ( 1 ) ;
125
+ } ) ) ;
126
+
127
+
128
+ it ( 'when ngInclude is on the same element, the content included content should get a child scope of the controller' ,
129
+ inject ( function ( $compile , $rootScope , $httpBackend ) {
130
+
131
+ var controllerScope ;
132
+
133
+ $rootScope . ExposeScopeController = function ( $scope ) {
134
+ controllerScope = $scope ;
135
+ } ;
136
+
137
+ element = $compile ( '<div><div ng-controller="ExposeScopeController" ng-include="\'url\'"></div></div>' ) ( $rootScope ) ;
138
+ $httpBackend . expect ( 'GET' , 'url' ) . respond ( '<div ng-init="name=\'Vojta\'"></div>' ) ;
139
+ $rootScope . $digest ( ) ;
140
+ $httpBackend . flush ( ) ;
141
+ expect ( controllerScope . name ) . toBeUndefined ( ) ;
142
+ } ) ) ;
88
143
} ) ;
0 commit comments