This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree 3 files changed +45
-1
lines changed
3 files changed +45
-1
lines changed Original file line number Diff line number Diff line change @@ -57,12 +57,32 @@ var /** holds major version number for IE or NaN for real browsers */
57
57
push = [ ] . push ,
58
58
toString = Object . prototype . toString ,
59
59
60
+
61
+ _angular = window . angular ,
60
62
/** @name angular */
61
63
angular = window . angular || ( window . angular = { } ) ,
62
64
angularModule ,
63
65
nodeName_ ,
64
66
uid = [ '0' , '0' , '0' ] ;
65
67
68
+ /**
69
+ * @ngdoc function
70
+ * @name angular.noConflict
71
+ * @function
72
+ *
73
+ * @description
74
+ * Restores the previous global value of angular and returns the current instance. Other libraries may already use the
75
+ * angular namespace. Or a previous version of angular is already loaded on the page. In these cases you may want to
76
+ * restore the previous namespace and keep a reference to angular.
77
+ *
78
+ * @return {Object } The current angular namespace
79
+ */
80
+ function noConflict ( ) {
81
+ var a = window . angular ;
82
+ window . angular = _angular ;
83
+ return a ;
84
+ }
85
+
66
86
/**
67
87
* @ngdoc function
68
88
* @name angular.forEach
Original file line number Diff line number Diff line change @@ -48,7 +48,8 @@ function publishExternalAPI(angular){
48
48
'isDate' : isDate ,
49
49
'lowercase' : lowercase ,
50
50
'uppercase' : uppercase ,
51
- 'callbacks' : { counter : 0 }
51
+ 'callbacks' : { counter : 0 } ,
52
+ 'noConflict' : noConflict
52
53
} ) ;
53
54
54
55
angularModule = setupModuleLoader ( window ) ;
Original file line number Diff line number Diff line change @@ -737,4 +737,27 @@ describe('angular', function() {
737
737
expect ( toJson ( { key : $rootScope } ) ) . toEqual ( '{"key":"$SCOPE"}' ) ;
738
738
} ) ) ;
739
739
} ) ;
740
+
741
+ describe ( 'noConflict' , function ( ) {
742
+ var globalAngular ;
743
+ beforeEach ( function ( ) {
744
+ globalAngular = angular ;
745
+ } ) ;
746
+
747
+ afterEach ( function ( ) {
748
+ angular = globalAngular ;
749
+ } ) ;
750
+
751
+ it ( 'should return angular' , function ( ) {
752
+ var a = angular . noConflict ( ) ;
753
+ expect ( a ) . toBe ( globalAngular ) ;
754
+ } ) ;
755
+
756
+ it ( 'should restore original angular' , function ( ) {
757
+ var a = angular . noConflict ( ) ;
758
+ expect ( angular ) . toBeUndefined ( ) ;
759
+ } ) ;
760
+
761
+ } ) ;
762
+
740
763
} ) ;
You can’t perform that action at this time.
0 commit comments