Code Monkey home page Code Monkey logo

ui-router.statehelper's Introduction

ui-router.stateHelper

A helper module for AngularUI Router, which allows you to define your states as an object tree.

Installation

  1. bower install angular-ui-router.stateHelper or npm install angular-ui-router.statehelper
  2. Reference stateHelper.min.js.
  3. Add a dependency on ui.router.stateHelper in your app module.

Usage

// NOTE: when using child states with views you should make sure that its parent has a template containing a `ui-view` directive.
angular.module('myApp', [ 'ui.router', 'ui.router.stateHelper' ])
    .config(function(stateHelperProvider){
        stateHelperProvider
            .state({
                name: 'root',
                templateUrl: 'root.html',
                children: [
                    {
                        name: 'contacts',
                        template: '<ui-view />',
                        children: [
                            {
                                name: 'list',
                                templateUrl: 'contacts.list.html'
                            }
                        ]
                    },
                    {
                        name: 'products',
                        templateUrl: 'products.html',
                        children: [
                            {
                                name: 'list',
                                templateUrl: 'products.list.html'
                            }
                        ]
                    }
                ]
            })
            .state({
                name: 'rootSibling',
                templateUrl: 'rootSibling.html'
            });
    });

Options

  • keepOriginalNames (default false)
  • siblingTraversal (default false)

Dot notation name conversion

By default, all state names are converted to use ui-router's dot notation (e.g. parentStateName.childStateName). This can be disabled by calling .state() with options options.keepOriginalNames = true. For example:

angular.module('myApp', ['ui.router', 'ui.router.stateHelper'])
	.config(function(stateHelperProvider){
		stateHelperProvider.state({
			name: 'root',
			templateUrl: 'root.html',
			children: [
				{
					name: 'contacts',
					templateUrl: 'contacts.html'
				}
			]
		}, { keepOriginalNames: true });
	});

Sibling Traversal

Child states may optionally receive a reference to the name of the previous state (if available) and the next state (if available) in order to facilitate sequential state traversal as in the case of building wizards or multi-part forms. Enable this by setting options.siblingTraversal = true.

Example:

angular.module('myApp', ['ui.router', 'ui.router.stateHelper'])
	.config(function(stateHelperProvider){
		stateHelperProvider.state({
			name: 'resume',
			children: [
				{
					name: 'contactInfo',
				},
				{
					name: 'experience',
				},
				{
					name: 'education',
				}
			]
		}, { siblingTraversal: true });
	});

console.log($state.get('resume.contactInfo').previousSibling) // undefined
console.log($state.get('resume.contactInfo').nextSibling) // 'resume.experience' 

console.log($state.get('resume.experience').previousSibling) // 'resume.contactInfo' 
console.log($state.get('resume.experience').nextSibling) // 'resume.education' 

console.log($state.get('resume.education').previousSibling) // 'resume.experience' 
console.log($state.get('resume.education').nextSibling) // undefined

Name change

Before 1.2.0 .setNestedState was used instead of .state. In 1.2.0 setNestedState was deprecated in favour of .state, and chaining was added. This makes it easier to switch between $stateProvider and stateHelperProvider.

ui-router.statehelper's People

Contributors

corinna000 avatar ajarrechea avatar zandroid avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.