ProWorks Blog

How to find if Umbraco 7 Debugging is Enabled in AngularJS or Javascript in the Backoffice

By Jason Prothero     Saturday, June 07, 2014     development, umbraco, angularjs, Umbraco 7
 15 16 ShareThis

When creating a new functionality in the Umbraco 7 backoffice such as a property editor or custom section, it is sometimes necessary to print out some debugging information to verify that the models are what you expect.

Rather than commenting out your {{myModel | json}} AngularJS bindings, why not simply only show them if Umbraco has debugging turned on?

Turns out, this is very easy as Umbraco already has a global ServerVariables collection that you can check:

Umbraco.Sys.ServerVariables.isDebuggingEnabled

If you want to show/hide information based on that in AngularJS, simply assign it to a property on the $scope of your controller:

$scope.showDebug = Umbraco.Sys.ServerVariables.isDebuggingEnabled;

Then check for it in your view:

<div data-ng-show="showDebug">{{myModel | json}}</div>

That's it!  

 15 16 ShareThis
comments powered by Disqus
comments powered by Disqus