@@ -184,12 +184,20 @@ function $RootScopeProvider(){
184
184
* When creating widgets, it is useful for the widget to not accidentally read parent
185
185
* state.
186
186
*
187
+ * @param {Scope } [parent=this] The {@link ng.$rootScope.Scope `Scope`} that will be the `$parent`
188
+ * of the newly created scope. Defaults to `this` scope if not provided.
189
+ * This is used when creating a transclude scope to correctly place it
190
+ * in the scope hierarchy while maintaining the correct prototypical
191
+ * inheritance.
192
+ *
187
193
* @returns {Object } The newly created child scope.
188
194
*
189
195
*/
190
- $new : function ( isolate ) {
196
+ $new : function ( isolate , parent ) {
191
197
var child ;
192
198
199
+ parent = parent || this ;
200
+
193
201
if ( isolate ) {
194
202
child = new Scope ( ) ;
195
203
child . $root = this . $root ;
@@ -213,13 +221,13 @@ function $RootScopeProvider(){
213
221
child = new this . $$ChildScope ( ) ;
214
222
}
215
223
child [ 'this' ] = child ;
216
- child . $parent = this ;
217
- child . $$prevSibling = this . $$childTail ;
218
- if ( this . $$childHead ) {
219
- this . $$childTail . $$nextSibling = child ;
220
- this . $$childTail = child ;
224
+ child . $parent = parent ;
225
+ child . $$prevSibling = parent . $$childTail ;
226
+ if ( parent . $$childHead ) {
227
+ parent . $$childTail . $$nextSibling = child ;
228
+ parent . $$childTail = child ;
221
229
} else {
222
- this . $$childHead = this . $$childTail = child ;
230
+ parent . $$childHead = parent . $$childTail = child ;
223
231
}
224
232
return child ;
225
233
} ,
0 commit comments