mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-09 15:24:43 +00:00
feat(noConflict): restore previous angular namespace reference
This commit is contained in:
parent
b7e1fb0515
commit
12ba6cec4f
3 changed files with 45 additions and 1 deletions
|
|
@ -57,12 +57,32 @@ var /** holds major version number for IE or NaN for real browsers */
|
||||||
push = [].push,
|
push = [].push,
|
||||||
toString = Object.prototype.toString,
|
toString = Object.prototype.toString,
|
||||||
|
|
||||||
|
|
||||||
|
_angular = window.angular,
|
||||||
/** @name angular */
|
/** @name angular */
|
||||||
angular = window.angular || (window.angular = {}),
|
angular = window.angular || (window.angular = {}),
|
||||||
angularModule,
|
angularModule,
|
||||||
nodeName_,
|
nodeName_,
|
||||||
uid = ['0', '0', '0'];
|
uid = ['0', '0', '0'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ngdoc function
|
||||||
|
* @name angular.noConflict
|
||||||
|
* @function
|
||||||
|
*
|
||||||
|
* @description
|
||||||
|
* Restores the previous global value of angular and returns the current instance. Other libraries may already use the
|
||||||
|
* angular namespace. Or a previous version of angular is already loaded on the page. In these cases you may want to
|
||||||
|
* restore the previous namespace and keep a reference to angular.
|
||||||
|
*
|
||||||
|
* @return {Object} The current angular namespace
|
||||||
|
*/
|
||||||
|
function noConflict() {
|
||||||
|
var a = window.angular;
|
||||||
|
window.angular = _angular;
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ngdoc function
|
* @ngdoc function
|
||||||
* @name angular.forEach
|
* @name angular.forEach
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,8 @@ function publishExternalAPI(angular){
|
||||||
'isDate': isDate,
|
'isDate': isDate,
|
||||||
'lowercase': lowercase,
|
'lowercase': lowercase,
|
||||||
'uppercase': uppercase,
|
'uppercase': uppercase,
|
||||||
'callbacks': {counter: 0}
|
'callbacks': {counter: 0},
|
||||||
|
'noConflict': noConflict
|
||||||
});
|
});
|
||||||
|
|
||||||
angularModule = setupModuleLoader(window);
|
angularModule = setupModuleLoader(window);
|
||||||
|
|
|
||||||
|
|
@ -737,4 +737,27 @@ describe('angular', function() {
|
||||||
expect(toJson({key: $rootScope})).toEqual('{"key":"$SCOPE"}');
|
expect(toJson({key: $rootScope})).toEqual('{"key":"$SCOPE"}');
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('noConflict', function() {
|
||||||
|
var globalAngular;
|
||||||
|
beforeEach(function() {
|
||||||
|
globalAngular = angular;
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(function() {
|
||||||
|
angular = globalAngular;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return angular', function() {
|
||||||
|
var a = angular.noConflict();
|
||||||
|
expect(a).toBe(globalAngular);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should restore original angular', function() {
|
||||||
|
var a = angular.noConflict();
|
||||||
|
expect(angular).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue