3

I want to (by default) have debug statements hidden

$logProvider.debugEnabled(false);

BUT I want the developers to access the debug statements via some sort of path param (or something like it). We have multiple "Dev" servers and want to quickly skim through the debug statements.

What i wanted to do was given a url such as:

myapp.com/mypage.html?debug=true

enable the $locationProvider to debug.

I wanted to do something like:

$urlParams = $location.search();
if($urlParams.debug) {
    $logProvider.debugEnabled(true);
}

in the config...but i cannot use the $location injection...is there anyway to do some sort of logic in the config section...or better yet, is there way to config and app on the fly?

Nate
  • 1,630
  • 2
  • 24
  • 41

2 Answers2

0

You can use UI-router for example something like this (coffeescript):

 'use strict'
 angular.module 'App'
 .config ($stateProvider, $urlRouterProvider) ->

   $stateProvider
   .state 'index',
     abstract: true
     url: '/'
     templateUrl: '<div ui-view></div>'
     controller: 'indexController'
     resolve:
       debugResolved: ($stateParams, $logProvider) ->
         if $stateParams.debug == 'true'
           $logProvider.debugEnabled(true)

This is just an example, I didn't tried it, but it should work as expected. You can check more about UI-router here: https://github.com/angular-ui/ui-router

Kamil
  • 1,633
  • 2
  • 21
  • 24
0

So I unfortunately could not get the solution that was posted above/below using the UI.router's $stateProvider.

Here is the solution I came up with:

Create my own Provider with contains a function to get Query Params, based on the solution found here: How can I get query string values in JavaScript?

app.provider("query",function(){
        return{
            getParamsByName: function(name){
                name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
                var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
                results = regex.exec(location.search);
                return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
            },

   $get: function(){ return {} }        
};
});

Then in my controller all i need to do was add the queryProvider to config,

and then call the getParamsByName("debug")

Community
  • 1
  • 1
Nate
  • 1,630
  • 2
  • 24
  • 41