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-default

v0.0.6

Published

AngularJS module that adds support for specifying default child views for abstract states when using ui-router.

Downloads

731

Readme

angular-ui-router-default

Build Status

Motivation

Abstract state are useful for resolving values used by multiple child states. However, since one cannot navigate to an abstract state ($state.go('abstract_parent')) any part of the application that transitions state ($state.go(), ui-sref, etc.) must explicitly specify a non-abstract child state ($state.go('abstract_parent.concrete-child')).

Abstract are also useful in top-level navigation links, since ui-sref-active is set for all their child states. However, since you can't directly navigate to the (ui-sref="abstract_state"), implementing these menu items usually requires an ng-click handler that navigates to a concrete state.

The options for How to: Set up a default/index child state are tedious, non-intuitive and depend on URL routing. There is a need for a more convenient way of defining default child states with some great ideas on how to configure these.

This module provides basic support for specifying the default child state as a string.

Loading the Module

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

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

Defining Default Child State

In your state definition for an abstract state, add a default property with the name of a child state (relative or absolute). The child state name can be provided statically as a string or dynamically as a function callback.

When a state transtion targets this abstract state, it will be redirected to the default child state instead.

$stateProvider
    .state('parent', {
      abstract: true,
      default: '.index',
      template: '<ui-view/>'
    })
    .state('parent.index', {
      // ...
    })
    .state('parent.page2', {
      // ...
    })
    .state('another', {
      abstract: true,
      default: ['$rootScope', function($rootScope) {
        return $rootScope.edit ? '.edit' : '.display';
      }]
    })
    .state('another.display', {
      // ...
    })
    .state('another.edit', {
      // ...
    })
    .state('anotherWithPromise',{
      abstract: true,
      default: ['$q',function($q){
        var defer = $q.defer();
        asyncFunctionThatReturnsPromise().then(function(){
          defer.resolve('anotherWithPromise.details');
        });
        return defer.promise;
      }]
    })
    .state('anotherWithPromise.details',{
      // ...
    })

Older version (< 0.0.5)

Older versions of this module specified the default state by assigning it to the abstract property:

$stateProvider
    .state('parent', {
      abstract: '.index',
      template: '<ui-view/>'
    })
    // ...

This behavior is still supported, but is deprecated, because it causes TypeScript conflicts. It is recommended that the { abstract: true, default: '.index' } format is used instead.

Using Default Child State

When a default child state is defined, the application can now navigate to the abstract parent state.

$state.go('parent');
<li ui-sref-active="active">
  <a ui-sref="parent">Go to Parent</a>
</li>

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.