Coder Social home page Coder Social logo

jyotisingh144 / sample-app-angular Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ui-router/sample-app-angular

0.0 0.0 0.0 8.32 MB

UI-Router for Angular - Sample Application (angular-cli)

Home Page: http://ui-router.github.io/sample-app-angular/#/mymessages/inbox/5648b50cc586cac4aed6836f

JavaScript 14.15% TypeScript 79.05% Shell 0.60% HTML 0.83% CSS 5.37%

sample-app-angular's Introduction

UI-Router for Angular - Sample Application

Travis badge Greenkeeper badge

This project was generated with angular-cli version 1.0.0-beta.30.

Live demo: http://ui-router.github.io/sample-app-angular/#/mymessages/inbox/5648b50cc586cac4aed6836f

Edit this project in your browser: https://stackblitz.com/github/ui-router/sample-app-angular

This sample app is intended to demonstrate a non-trivial ui-router application.

  • Multiple sub-modules
  • Managed state lifecycle
  • Application data lifecycle
  • Authentication (simulated)
  • Authenticated and unauthenticated states
  • REST data retrieval (simulated)
  • Lazy loaded Angular modules (contacts/mymessages/prefs submodules)

Visualizer

We're using the State and Transition Visualizer to visually represent the current state tree, as well as the transitions between states. Explore how transitions work by hovering over them, and clicking to expand details (params and resolves).

Note how states are entered when they were previously not active, exited and re-entered when parameters change, and how parent states whose parameters did not change are retained. Each of these (exited, entered, retained) correspond to a Transition Hook.

Structure

There are many ways to structure a ui-router app. We aren't super opinionated on application structure. Use what works for you. We organized ours in the following way:

  • Feature modules
    • Each feature gets its own directory and Angular Module (@NgModule)
    • Features contain states and components
    • Specific types of helper code (directives, services, etc) used only within a feature may live in a subdirectory named after its type
  • Leveraging ES6 modules
    • States for a module are defined in separate file
    • Each component is defined in its own file
    • Components are referenced in states where they are composed into the state definition
    • States export themselves
    • Each feature @NgModule imports and declares all the states for the feature

UI-Router Patterns

  • Defining custom, app-specific global behaviors
    • Add metadata to a state, or state tree (such as authRequired)
    • Check for metadata in transition hooks
    • Example: routerhooks/authRequired.js
      • If a transition to a state with a truthy data.authRequired: true property is started and the user is not currently authenticated
  • Defining a default substate for a top-level state
    • Example: declaring redirectTo: 'welcome' in app.states.ts
  • Defining a default parameter for a state
    • Example: folderId parameter defaults to 'inbox' in mymessages.states.ts (folder state)
  • Application data lifecycle
    • Data loading is managed by the state declaration, via the resolve: block
    • Data is fetched before the state is entered
    • Data is fetched according to state parameters
    • The state is entered when the data is ready
    • The resolved data is injected into the components
    • The resolve data remains loaded until the state is exited
  • Lazy Loaded states
    • The main submodules (and all their states and components) are lazy loaded
    • The future state includes a loadChildren property which is used to lazy load the module

sample-app-angular's People

Contributors

dependabot-support avatar dependabot[bot] avatar christopherthielen avatar greenkeeper[bot] avatar greenkeeperio-bot avatar dependencies-bot avatar angular-cli 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.