npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

angular-ui-router-title

v0.1.1

Published

AngularJS module for updating browser title/history based on the current ui-router state.

Downloads

4,889

Readme

angular-ui-router-title

Build Status

AngularJS module for updating browser title/history based on the current ui-router state.

Motivation

Using ui-router states with url configurations enables browser history support and bookmarking of application state. It is important that the title in the browser history/bookmark represent the application state so that the user can tell where she's navigating to.

The module provides a $title variable on the $rootScope that is populated based on the $title value resolved in $state.$current (or one of its parent states). If the current state doesn't resolve a $title, then $rootScope.$title will be undefined.

The module also provides a $breadcrumbs array that is populated based on the $title of $state.$current and its parent states.

The module sets the document.title to the value of the $title variable or, if configured, to the value returned by a documentTitle(title) callback. The browser sets bookmark and browser history text based on the document.title.

Installing the Module

Installation can be done through bower:

bower install angular-ui-router-title

In your page add:

  <script src="bower_components/angular-ui-router-title/angular-ui-router-title.js"></script>

Loading the Module

This module declares itself as ui.router.title, so it can be declared as a dependency of your application as normal:

var app = angular.module('myApp', ['ng', 'ui.router.title']);

Specifying the $title in the state definition

A state defines its title by declaring a $title value in its resolve block. It's a good idea for the $title to include information from the current state, so it may need to inject the $stateParam or another value that was resolved from them.

$stateProvider
  .state('home', {
    ...
    resolve: {
      // Constant title
      $title: function() { return 'Home'; }
    }
  })
  .state('about', {
    url: '/about',
    ...
    resolve: {
      // Constant title
      $title: function() { return 'About'; }
    }
  })
  .state('contacts', {
    url: '/contacts',
    ...
    resolve: {
      // List of contacts
      contacts: ['Contacts', function(Contacts) {
        // Use Contacts service to retrieve list
        return Contacts.query();
      }],
      // Dynamic title showing number of contacts
      $title: ['contacts', function(contacts) {
        return 'Contacts (' + contacts.length + ')';
      }]
    }
  })
  .state('contact', {
    url: '/contact/:contactId',
    ...
    resolve: {
      // Single contact
      contact: ['Contacts', '$stateParams', function(Contacts, $stateParams) {
        // Use Contacts service to retrieve a contact
        return Contacts.get({ id: $stateParams.contactId });
      }],
      // Dynamic title showing the name of contact
      $title: ['contact', function(contact) {
        return contact.name;
      }]
    }
  })
  .state('contact.edit', {
    url: '/edit',
    ...
    resolve: {
      // Dynamic title appending to parent state's title
      $title: ['$title', function($title) {
        return $title + " (edit)";
      }]
    }
  })

Configuring a custom document.title

By default, the module will set the document.title to the value of $rootScope.$title. A common convention is to include the application name in the document.title. Customization of the document.title can be achieved via the $titleProvier.documentTitle callback specification.

angular.module('myApp', ['ng', 'ui.router.title'])
  .config(function($titleProvider) {
    $titleProvider.documentTitle(function($rootScope) {
      return $rootScope.$title ? $rootScope.$title + " - My Application" : "My Application";
    });
  });

Using the $title in a header

The $title property contains the resolve title and cen be used, for example, to set the contents of an <h1> tag.

  <h1 ng-bind="($title || 'Home') + ' - My Application'">My Application</h1>

Using the $breadcrumbs

The $breadcrumbs array contains objects, one for each state that resolves a $title value. Each entry contains:

  • title: $title value of this state
  • state: name of the state
  • stateParams: $stateParams of the state.
<ol class="breadcrumb">
	<li ng-repeat="crumb in $breadcrumbs" ng-class="{ 'active' : $last }">
		<a ng-if="!$last" href="{{$state.href(crumb.state, crumb.stateParams)}}">{{crumb.title}}</a>
		<span ng-if="$last">{{crumb.title}}</span>
	</li>
</ol>

Copyright & License

Copyright 2015 Stepan Riha. All Rights Reserved.

This may be redistributed under the MIT licence. For the full license terms, see the LICENSE file which should be alongside this readme.