1

I am building an angular plugin named breadcrumb here, it works fine until I update ui-router version to '1.0.0-beta.2'. the cause is that I can't get resolved data from $state.$current.

in html

specify display name property to data.displayName in html <breadcrumbs display-name-property="data.displayName"></breadcrumbs>

state config

displayName is dynamic .state('app.dict.list.tree', { ... data: { displayName: '{{title}}' }, resolve: { title: ['$transition$', $transition$ => $transition$.params().title], } })

directive link function

i use $interpolate service to compile propertyReference(in this case '{{title}}') with the context $state.$current.locals.global. var currentState = $state.$current; interpolationContext = (typeof currentState.locals !== 'undefined') ? currentState.locals.globals : currentState; displayName = $interpolate(propertyReference)(interpolationContext);

update ui-router to the latest version, this code won't work anymore, currentState.locals is undefined, and I can't find a way to access resolved data in currentState object.

does anybody know how to do it? any help will be appreciated.

1

2 Answers 2

2

I found $state.getCurrentPath() gives a list of pathNodes which includes resolved data.

It is similar to Transition's treeChanges().to which is available only when transition occurs

Sign up to request clarification or add additional context in comments.

Comments

0
if(legacyRouter){ scope.$on('$stateChangeSuccess', function() { updateBreadcrumbsArray(); }); }else{ $injector.get('$transitions').onSuccess({}, function(trans){ resolved(trans, updateBreadcrumbsArray) }) } /** * get all resolved data in state declare and use them to compile display name * */ function resolved(trans, fn){ var tokens = trans.getResolveTokens(); var resolves = {}; var promises = tokens.map(function(token){ var resolved = trans.injector().get(token); resolves[token] = resolved; return resolved; }); $q.all(promises).then(function(){ fn(resolves); }) } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.