Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 41c1b88

Browse files
petebacondarwinvojtajina
authored andcommitted
feat: add angular.reloadWithDebugInfo()
1 parent fce8915 commit 41c1b88

File tree

4 files changed

+63
-1
lines changed

4 files changed

+63
-1
lines changed

src/.jshintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
"getBlockNodes": false,
8989
"createMap": false,
9090
"VALIDITY_STATE_PROPERTY": false,
91+
"reloadWithDebugInfo": false,
9192

9293
"skipDestroyOnNextJQueryCleanData": true,
9394

src/Angular.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,6 +1402,14 @@ function bootstrap(element, modules, config) {
14021402
modules.unshift(['$provide', function($provide) {
14031403
$provide.value('$rootElement', element);
14041404
}]);
1405+
1406+
if (config.debugInfoEnabled) {
1407+
// Pushing so that this overrides `debugInfoEnabled` setting defined in user's `modules`.
1408+
modules.push(['$compileProvider', function($compileProvider) {
1409+
$compileProvider.debugInfoEnabled(true);
1410+
}]);
1411+
}
1412+
14051413
modules.unshift('ng');
14061414
var injector = createInjector(modules, config.strictDi);
14071415
injector.invoke(['$rootScope', '$rootElement', '$compile', '$injector',
@@ -1415,8 +1423,14 @@ function bootstrap(element, modules, config) {
14151423
return injector;
14161424
};
14171425

1426+
var NG_ENABLE_DEBUG_INFO = /^NG_ENABLE_DEBUG_INFO!/;
14181427
var NG_DEFER_BOOTSTRAP = /^NG_DEFER_BOOTSTRAP!/;
14191428

1429+
if (window && NG_ENABLE_DEBUG_INFO.test(window.name)) {
1430+
config.debugInfoEnabled = true;
1431+
window.name = window.name.replace(NG_ENABLE_DEBUG_INFO, '');
1432+
}
1433+
14201434
if (window && !NG_DEFER_BOOTSTRAP.test(window.name)) {
14211435
return doBootstrap();
14221436
}
@@ -1430,6 +1444,32 @@ function bootstrap(element, modules, config) {
14301444
};
14311445
}
14321446

1447+
/**
1448+
* @ngdoc function
1449+
* @name angular.reloadWithDebugInfo
1450+
* @module ng
1451+
* @description
1452+
* Use this function to reload the current application with debug information turned on.
1453+
*
1454+
* To improve performance adding various debugging information can be disabled.
1455+
* See {@link $compileProvider#debugInfoEnabled}.
1456+
*
1457+
* This overrides any setting of `$compileProvider.debugInfoEnabled()` that you defined in your
1458+
* modules. If you wish to debug an application via this information then you should open up a debug
1459+
* console in the browser then call this method directly in this console:
1460+
*
1461+
* ```js
1462+
* angular.reloadWithDebugInfo();
1463+
* ```
1464+
*
1465+
* The page should reload and the debug information should now be available.
1466+
*
1467+
*/
1468+
function reloadWithDebugInfo(doReload) {
1469+
window.name = 'NG_ENABLE_DEBUG_INFO!' + window.name;
1470+
if ( doReload !== false ) window.location.reload();
1471+
}
1472+
14331473
var SNAKE_CASE_REGEXP = /[A-Z]/g;
14341474
function snake_case(name, separator) {
14351475
separator = separator || '_';

src/AngularPublic.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ function publishExternalAPI(angular){
137137
'uppercase': uppercase,
138138
'callbacks': {counter: 0},
139139
'$$minErr': minErr,
140-
'$$csp': csp
140+
'$$csp': csp,
141+
'reloadWithDebugInfo': reloadWithDebugInfo
141142
});
142143

143144
angularModule = setupModuleLoader(window);

test/AngularSpec.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,6 +1099,26 @@ describe('angular', function() {
10991099
});
11001100

11011101

1102+
describe("reloadWithDebugInfo", function() {
1103+
1104+
it("should reload the current page with debugInfo turned on", function() {
1105+
1106+
element = jqLite('<div>{{1+2}}</div>');
1107+
angular.bootstrap(element);
1108+
expect(element.hasClass('ng-scope')).toBe(false);
1109+
dealoc(element);
1110+
1111+
// We pass the false to prevent the page actually reloading
1112+
angular.reloadWithDebugInfo(false);
1113+
1114+
element = jqLite('<div>{{1+2}}</div>');
1115+
angular.bootstrap(element);
1116+
expect(element.hasClass('ng-scope')).toBe(true);
1117+
dealoc(element);
1118+
});
1119+
});
1120+
1121+
11021122
describe('startingElementHtml', function(){
11031123
it('should show starting element tag only', function(){
11041124
expect(startingTag('<ng-abc x="2A"><div>text</div></ng-abc>')).

0 commit comments

Comments
 (0)