@@ -790,10 +790,10 @@ var ngSwitch = angularWidget('ng:switch', function (element){
790790 forEach ( cases , function ( switchCase ) {
791791 if ( ! found && switchCase . when ( childScope , value ) ) {
792792 found = true ;
793- var caseElement = switchCase . element . cloneNode ( ) ;
794- element . append ( caseElement ) ;
795793 childScope . $tryEval ( switchCase . change , element ) ;
796- switchCase . template ( childScope , caseElement ) ;
794+ switchCase . template ( childScope , function ( caseElement ) {
795+ element . append ( caseElement ) ;
796+ } ) ;
797797 }
798798 } ) ;
799799 } ) ;
@@ -886,11 +886,11 @@ angularWidget('a', function() {
886886 </doc:scenario>
887887 </doc:example>
888888 */
889- angularWidget ( " @ng:repeat" , function ( expression , element ) {
889+ angularWidget ( ' @ng:repeat' , function ( expression , element ) {
890890 element . removeAttr ( 'ng:repeat' ) ;
891- element . replaceWith ( jqLite ( " <!-- ng:repeat: " + expression + " --!>" ) ) ;
891+ element . replaceWith ( jqLite ( ' <!-- ng:repeat: ' + expression + ' --!>' ) ) ;
892892 var linker = this . compile ( element ) ;
893- return function ( reference ) {
893+ return function ( iterStartElement ) {
894894 var match = expression . match ( / ^ \s * ( .+ ) \s + i n \s + ( .* ) \s * $ / ) ,
895895 lhs , rhs , valueIdent , keyIdent ;
896896 if ( ! match ) {
@@ -910,10 +910,9 @@ angularWidget("@ng:repeat", function(expression, element){
910910 var children = [ ] , currentScope = this ;
911911 this . $onEval ( function ( ) {
912912 var index = 0 ,
913- cloneElement ,
914913 childCount = children . length ,
915- lastElement = reference ,
916- collection = this . $tryEval ( rhs , reference ) ,
914+ lastIterElement = iterStartElement ,
915+ collection = this . $tryEval ( rhs , iterStartElement ) ,
917916 is_array = isArray ( collection ) ,
918917 collectionLength = 0 ,
919918 childScope ,
@@ -934,6 +933,7 @@ angularWidget("@ng:repeat", function(expression, element){
934933 childScope = children [ index ] ;
935934 childScope [ valueIdent ] = collection [ key ] ;
936935 if ( keyIdent ) childScope [ keyIdent ] = key ;
936+ lastIterElement = childScope . $element ;
937937 } else {
938938 // grow children
939939 childScope = createScope ( currentScope ) ;
@@ -943,21 +943,22 @@ angularWidget("@ng:repeat", function(expression, element){
943943 childScope . $position = index == 0
944944 ? 'first'
945945 : ( index == collectionLength - 1 ? 'last' : 'middle' ) ;
946- lastElement . after ( cloneElement = element . cloneNode ( ) ) ;
947- cloneElement . attr ( 'ng:repeat-index' , index ) ;
948- linker ( childScope , cloneElement ) ;
949946 children . push ( childScope ) ;
947+ linker ( childScope , function ( clone ) {
948+ clone . attr ( 'ng:repeat-index' , index ) ;
949+ lastIterElement . after ( clone ) ;
950+ lastIterElement = clone ;
951+ } ) ;
950952 }
951953 childScope . $eval ( ) ;
952- lastElement = childScope . $element ;
953954 index ++ ;
954955 }
955956 }
956957 // shrink children
957958 while ( children . length > index ) {
958959 children . pop ( ) . $element . remove ( ) ;
959960 }
960- } , reference ) ;
961+ } , iterStartElement ) ;
961962 } ;
962963} ) ;
963964
0 commit comments