Q:

Accessing ui-router state params from an attribute-type directive (NOT a component)

We're upgrading from a very old version of UI Router to v1.0.5, and I'm having an issue trying to replace our deprecated $stateParams uses. To use a simplified example, we have a unique-name attribute-type directive we use on a form field to do a validation check to make sure the text in the field is a unique name. The idea is we're either adding a new doohickey or changing the name of an existing doohickey, and we want to ensure that no other doohickey has the same name.
In our old code, we could get the doohickeyId value from the $stateParams like this:
function uniqueName(doohickeySearchService, $stateParams, $q) {
        return {
            restrict: 'A',
            require: 'ngModel',
            link: function (scope, elm, attrs, ctrl) {
                ctrl.$asyncValidators.uniqueName = function (modelValue) {
                    // use doohickeySearchService to look up foundDoohickey by name
                    // then...
                    return foundDoohickey.id !== $stateParams.doohickeyId;
                };
            }
        };
    }

Probably way over-simplified, but the core of the problem is there: how do we get access to the doohickeyId value without using the deprecated $stateParams? There's a parent state that's getting it from the url , which is something like /doohickey/{doohickeyId:int}/edit, as specified in the state definition. 
I can use $state to get the $current state, and an array of states from the path property, and I can even see the doohickeyId param in one of the states in the path. Unfortunately, if I take the value() of the param, it comes back undefined, even though $stateParams has the correct doohickeyId value. I've also tried adding doohickeyId as a resolve on the parent state, but unfortunately that doesn't give me any data on the attribute-type directive where I need it.
Reading the docs and googling is turning up references to accessing parent data from child states, or a component, but I'm trying to get access from an attribute-type directive, not a state/component. Is there a way to do this without giving our code base a major overhaul?

A:

Have you tried this solution from the UI-Router documentation?

Instead of using the global $stateParams service object,
inject $uiRouterGlobals and use UIRouterGlobals.params
MyService.$inject = ['$uiRouterGlobals'];
function MyService($uiRouterGlobals) {
  return {
    paramValues: function () {
      return $uiRouterGlobals.params;
    }
  }
}

Instead of using the per-transition $stateParams object,
inject the current Transition (as $transition$) and use Transition.params
MyController.$inject = ['$transition$'];
function MyController($transition$) {
  var username = $transition$.params().username;
  // .. do something with username
}

https://ui-router.github.io/ng1/docs/latest/modules/injectables.html#_stateparams

