1
1
/**
2
- * @license AngularJS v1.2.27 -build.496 +sha.d7c084f
2
+ * @license AngularJS v1.3.0 -build.3342 +sha.feba017
3
3
* (c) 2010-2014 Google, Inc. http://angularjs.org
4
4
* License: MIT
5
5
*/
22
22
*/
23
23
/* global -ngRouteModule */
24
24
var ngRouteModule = angular . module ( 'ngRoute' , [ 'ng' ] ) .
25
- provider ( '$route' , $RouteProvider ) ;
25
+ provider ( '$route' , $RouteProvider ) ,
26
+ $routeMinErr = angular . $$minErr ( 'ngRoute' ) ;
26
27
27
28
/**
28
29
* @ngdoc provider
29
30
* @name $routeProvider
30
- * @kind function
31
31
*
32
32
* @description
33
33
*
@@ -216,10 +216,14 @@ function $RouteProvider(){
216
216
* Sets route definition that will be used on route change when no other route definition
217
217
* is matched.
218
218
*
219
- * @param {Object } params Mapping information to be assigned to `$route.current`.
219
+ * @param {Object|string } params Mapping information to be assigned to `$route.current`.
220
+ * If called with a string, the value maps to `redirectTo`.
220
221
* @returns {Object } self
221
222
*/
222
223
this . otherwise = function ( params ) {
224
+ if ( typeof params === 'string' ) {
225
+ params = { redirectTo : params } ;
226
+ }
223
227
this . when ( null , params ) ;
224
228
return this ;
225
229
} ;
@@ -230,10 +234,9 @@ function $RouteProvider(){
230
234
'$routeParams' ,
231
235
'$q' ,
232
236
'$injector' ,
233
- '$http' ,
234
- '$templateCache' ,
237
+ '$templateRequest' ,
235
238
'$sce' ,
236
- function ( $rootScope , $location , $routeParams , $q , $injector , $http , $templateCache , $sce ) {
239
+ function ( $rootScope , $location , $routeParams , $q , $injector , $templateRequest , $sce ) {
237
240
238
241
/**
239
242
* @ngdoc service
@@ -438,6 +441,36 @@ function $RouteProvider(){
438
441
reload : function ( ) {
439
442
forceReload = true ;
440
443
$rootScope . $evalAsync ( updateRoute ) ;
444
+ } ,
445
+
446
+ /**
447
+ * @ngdoc method
448
+ * @name $route#updateParams
449
+ *
450
+ * @description
451
+ * Causes `$route` service to update the current URL, replacing
452
+ * current route parameters with those specified in `newParams`.
453
+ * Provided property names that match the route's path segment
454
+ * definitions will be interpolated into the location's path, while
455
+ * remaining properties will be treated as query params.
456
+ *
457
+ * @param {Object } newParams mapping of URL parameter names to values
458
+ */
459
+ updateParams : function ( newParams ) {
460
+ if ( this . current && this . current . $$route ) {
461
+ var searchParams = { } , self = this ;
462
+
463
+ angular . forEach ( Object . keys ( newParams ) , function ( key ) {
464
+ if ( ! self . current . pathParams [ key ] ) searchParams [ key ] = newParams [ key ] ;
465
+ } ) ;
466
+
467
+ newParams = angular . extend ( { } , this . current . params , newParams ) ;
468
+ $location . path ( interpolate ( this . current . $$route . originalPath , newParams ) ) ;
469
+ $location . search ( angular . extend ( { } , $location . search ( ) , searchParams ) ) ;
470
+ }
471
+ else {
472
+ throw $routeMinErr ( 'norout' , 'Tried updating route when with no current route' ) ;
473
+ }
441
474
}
442
475
} ;
443
476
@@ -513,7 +546,7 @@ function $RouteProvider(){
513
546
514
547
angular . forEach ( locals , function ( value , key ) {
515
548
locals [ key ] = angular . isString ( value ) ?
516
- $injector . get ( value ) : $injector . invoke ( value ) ;
549
+ $injector . get ( value ) : $injector . invoke ( value , null , null , key ) ;
517
550
} ) ;
518
551
519
552
if ( angular . isDefined ( template = next . template ) ) {
@@ -527,8 +560,7 @@ function $RouteProvider(){
527
560
templateUrl = $sce . getTrustedResourceUrl ( templateUrl ) ;
528
561
if ( angular . isDefined ( templateUrl ) ) {
529
562
next . loadedTemplateUrl = templateUrl ;
530
- template = $http . get ( templateUrl , { cache : $templateCache } ) .
531
- then ( function ( response ) { return response . data ; } ) ;
563
+ template = $templateRequest ( templateUrl ) ;
532
564
}
533
565
}
534
566
if ( angular . isDefined ( template ) ) {
@@ -690,7 +722,6 @@ ngRouteModule.directive('ngView', ngViewFillContentFactory);
690
722
<pre>$location.path() = {{main.$location.path()}}</pre>
691
723
<pre>$route.current.templateUrl = {{main.$route.current.templateUrl}}</pre>
692
724
<pre>$route.current.params = {{main.$route.current.params}}</pre>
693
- <pre>$route.current.scope.name = {{main.$route.current.scope.name}}</pre>
694
725
<pre>$routeParams = {{main.$routeParams}}</pre>
695
726
</div>
696
727
</file>
@@ -823,27 +854,28 @@ function ngViewFactory( $route, $anchorScroll, $animate) {
823
854
link : function ( scope , $element , attr , ctrl , $transclude ) {
824
855
var currentScope ,
825
856
currentElement ,
826
- previousElement ,
857
+ previousLeaveAnimation ,
827
858
autoScrollExp = attr . autoscroll ,
828
859
onloadExp = attr . onload || '' ;
829
860
830
861
scope . $on ( '$routeChangeSuccess' , update ) ;
831
862
update ( ) ;
832
863
833
864
function cleanupLastView ( ) {
834
- if ( previousElement ) {
835
- previousElement . remove ( ) ;
836
- previousElement = null ;
865
+ if ( previousLeaveAnimation ) {
866
+ $animate . cancel ( previousLeaveAnimation ) ;
867
+ previousLeaveAnimation = null ;
837
868
}
869
+
838
870
if ( currentScope ) {
839
871
currentScope . $destroy ( ) ;
840
872
currentScope = null ;
841
873
}
842
874
if ( currentElement ) {
843
- $animate . leave ( currentElement , function ( ) {
844
- previousElement = null ;
875
+ previousLeaveAnimation = $animate . leave ( currentElement ) ;
876
+ previousLeaveAnimation . then ( function ( ) {
877
+ previousLeaveAnimation = null ;
845
878
} ) ;
846
- previousElement = currentElement ;
847
879
currentElement = null ;
848
880
}
849
881
}
@@ -863,7 +895,7 @@ function ngViewFactory( $route, $anchorScroll, $animate) {
863
895
// function is called before linking the content, which would apply child
864
896
// directives to non existing elements.
865
897
var clone = $transclude ( newScope , function ( clone ) {
866
- $animate . enter ( clone , null , currentElement || $element , function onNgViewEnter ( ) {
898
+ $animate . enter ( clone , null , currentElement || $element ) . then ( function onNgViewEnter ( ) {
867
899
if ( angular . isDefined ( autoScrollExp )
868
900
&& ( ! autoScrollExp || scope . $eval ( autoScrollExp ) ) ) {
869
901
$anchorScroll ( ) ;
0 commit comments