@@ -9,40 +9,42 @@ function Template(priority) {
99 this . children = [ ] ;
1010 this . inits = [ ] ;
1111 this . priority = priority ;
12+ this . newScope = false ;
1213}
1314
1415Template . prototype = {
1516 init : function ( element , scope ) {
1617 var inits = { } ;
17- this . collectInits ( element , inits ) ;
18+ this . collectInits ( element , inits , scope ) ;
1819 foreachSorted ( inits , function ( queue ) {
19- foreach ( queue , function ( fn ) {
20- fn ( scope ) ;
21- } ) ;
20+ foreach ( queue , function ( fn ) { fn ( ) ; } ) ;
2221 } ) ;
2322 } ,
2423
25- collectInits : function ( element , inits ) {
26- var queue = inits [ this . priority ] ;
24+ collectInits : function ( element , inits , scope ) {
25+ var queue = inits [ this . priority ] , childScope = scope ;
2726 if ( ! queue ) {
2827 inits [ this . priority ] = queue = [ ] ;
2928 }
3029 element = jqLite ( element ) ;
30+ if ( this . newScope ) {
31+ childScope = createScope ( scope ) ;
32+ scope . $onEval ( childScope . $eval ) ;
33+ }
3134 foreach ( this . inits , function ( fn ) {
32- queue . push ( function ( scope ) {
33- scope . $tryEval ( function ( ) {
34- return fn . call ( scope , element ) ;
35+ queue . push ( function ( ) {
36+ childScope . $tryEval ( function ( ) {
37+ return fn . call ( childScope , element ) ;
3538 } , element ) ;
3639 } ) ;
3740 } ) ;
38-
3941 var i ,
4042 childNodes = element [ 0 ] . childNodes ,
4143 children = this . children ,
4244 paths = this . paths ,
4345 length = paths . length ;
4446 for ( i = 0 ; i < length ; i ++ ) {
45- children [ i ] . collectInits ( childNodes [ paths [ i ] ] , inits ) ;
47+ children [ i ] . collectInits ( childNodes [ paths [ i ] ] , inits , childScope ) ;
4648 }
4749 } ,
4850
@@ -121,7 +123,8 @@ Compiler.prototype = {
121123 element :function ( type ) { return jqLite ( document . createElement ( type ) ) ; } ,
122124 text :function ( text ) { return jqLite ( document . createTextNode ( text ) ) ; } ,
123125 descend : function ( value ) { if ( isDefined ( value ) ) descend = value ; return descend ; } ,
124- directives : function ( value ) { if ( isDefined ( value ) ) directives = value ; return directives ; }
126+ directives : function ( value ) { if ( isDefined ( value ) ) directives = value ; return directives ; } ,
127+ scope : function ( value ) { if ( isDefined ( value ) ) template . newScope = template . newScope || value ; return template . newScope ; }
125128 } ;
126129 try {
127130 priority = element . attr ( 'ng:eval-order' ) || priority || 0 ;
0 commit comments