This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree 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 */
5757 push = [ ] . push ,
5858 toString = Object . prototype . toString ,
5959
60+
61+ _angular = window . angular ,
6062 /** @name angular */
6163 angular = window . angular || ( window . angular = { } ) ,
6264 angularModule ,
6365 nodeName_ ,
6466 uid = [ '0' , '0' , '0' ] ;
6567
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+
6686/**
6787 * @ngdoc function
6888 * @name angular.forEach
Original file line number Diff line number Diff line change @@ -48,7 +48,8 @@ function publishExternalAPI(angular){
4848 'isDate' : isDate ,
4949 'lowercase' : lowercase ,
5050 'uppercase' : uppercase ,
51- 'callbacks' : { counter : 0 }
51+ 'callbacks' : { counter : 0 } ,
52+ 'noConflict' : noConflict
5253 } ) ;
5354
5455 angularModule = setupModuleLoader ( window ) ;
Original file line number Diff line number Diff line change @@ -737,4 +737,27 @@ describe('angular', function() {
737737 expect ( toJson ( { key : $rootScope } ) ) . toEqual ( '{"key":"$SCOPE"}' ) ;
738738 } ) ) ;
739739 } ) ;
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+
740763} ) ;
You can’t perform that action at this time.
0 commit comments