nonplus / angular-ui-router-title

AngularJS module for updating browser title/history based on the current ui-router state.
122 stars 30 forks source link

[feature request] description #3

Closed dmarcelino closed 9 years ago

dmarcelino commented 9 years ago

Sorry for spamming you @nonplus, I was wondering if it would make sense to add support for metadata such as $description?

Right now I'm working around it by resolving $title to an object such as:

$title: ['thing', function(thing) {
  return { 
    title: thing.name,
    description: thing.description
  };
}]

And then:

    <title ng-bind="$title.title">MyApp</title>
    <meta name="description" content="{{$title.description}}">

Is this valid in the sense that future changes won't enforce $title to be a string?

dmarcelino commented 9 years ago

Looking at the code in angular-ui-router-title.js#L18:

title: getTitleValue(state.locals.globals.$title),

It seems my workaround breaks the breadcrumbs... :disappointed:

I wonder if it would make sense to support an attribute named $meta in addition/alternative to $title which would be an object instead of a string... Would that be within scope?

nonplus commented 9 years ago

I don't anticipate any changes in the future that would make assumptions about $title being a string, so having $title return a {title, description} object is perfectly valid.

I don't want to complicate the module by being responsible for additional meta data like the $description since ui-state already has good support for supporting state-specific data.

What my module adds is the convenience of putting $title on the root scope and, more importantly, delaying when the $rootScope.$title is set so that it doesn't update the page title prematurely. This really only comes into play when updating the <title> tag.

dmarcelino commented 9 years ago

For dynamic values, the state's resolve property can inject dynamic values which can be accessed via the (undocumented) $state.$current.locals.globals.

I didn't know about $state.$current.locals.globals, let me try it, it will likely fix my current issue.

dmarcelino commented 9 years ago

It does fix the issue, thanks.