Coder Social home page Coder Social logo
sample-app-angularjs

ui-router / sample-app-angularjs Goto Github PK

View Code? Open in 1sVSCode Editor NEW
240.0 10.0 106.0 6.68 MB

UI-Router for AngularJS - Sample Application

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

CSS 6.63% JavaScript 91.59% HTML 1.10% Shell 0.68%

sample-app-angularjs's Introduction

UI-Router for AngularJS 1.0 - Sample Application

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

Greenkeeper badge Travis badge

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 AngularJS module (contacts submodule)
  • Sticky States with Deep State Redirect

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.

Structure

The application is written in ES6 (transpiled using babel), and utilizes ES6 modules. We are loading the modules and creating bundles using webpack 4.

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:

  • Sub-module (feature) organization
    • Each feature gets its own directory.
    • 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 (/mymessages/directives)
  • Leveraging ES6 modules
    • Each state is defined in its own file
    • Each component (controller + template) is defined in its own file
    • Components exported themselves
    • Components are then imported into a states where they are composed into the state definition.
    • States export themselves
    • The feature.module.js imports all states for the feature and registers then with the $stateProvider
  • A single angular module is defined for the entire application
    • Created, then exported from bootstrap/ngmodule.js
    • The ng module is imported into some other module whenever services, config blocks, directives, etc need to be registered with angular.

UI-Router Patterns

  • Defining custom, app-specific global behaviors
    • Add metadata to a state, or state tree
    • Check for metadata in transition hooks
    • Example: routerhooks/redirectTo.js
      • If a transition directly to a state with a redirectTo property is started, the transition will be redirected to the state which the property names.
    • 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.js
  • Defining a default parameter for a state
    • Example: folderId parameter defaults to 'inbox' in mymessages.states.js (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 Contacts submodule (all its states and components) are lazy loaded
    • The Contacts "future state" (a placeholder) is added in bootstrap/ngmodule.js
    • ocLazyLoad is used to lazy load the angular module
  • Deep State Redirect (DSR)
    • DSR used on the contacts and mymessages top level states
    • When a substate of a DSR state is activated, the state and parameters are memorized
    • When contacts or mymessages is activated again, the transition redirects to the memorized deep state and params
  • Sticky States
    • Sticky States are enabled on the contacts and mymessages top level states
    • The modules' views (including DOM) and state are retained when a different module is activated
    • When returning to the module, the inactive state is reactivated
    • The views are restored (unhidden)

sample-app-angularjs's People

Contributors

dependabot-preview[bot] avatar christopherthielen avatar dependabot[bot] avatar uirouterbot avatar greenkeeper[bot] avatar greenkeeperio-bot avatar elboman avatar SKoschnicke avatar dependencies-bot avatar OskarPersson avatar

Stargazers

dbaspider avatar  avatar KingxBeta avatar Poojan Shah avatar Narayan Sharma avatar Nathan Kleinschmidt avatar Bruno Martin avatar hack-club avatar  avatar Anderson Dias avatar  avatar Andrew avatar Edwin Sheldon avatar Chad Robinson avatar Valera avatar Drew Miller avatar Fan, Yi-Jie avatar  avatar AJ Klein avatar Judes Tumuhairwe avatar hwael avatar Harish avatar  avatar  avatar Thomas yang avatar oyaay avatar Vinicius Seixas avatar Sheehan Toufiq Khan avatar Ben Merchant avatar Jordan Hoover avatar lvzhenbang avatar gerich-home avatar Blake Kruppa avatar  avatar GAURAV avatar  avatar chetna avatar Naldo Portela avatar  avatar Danielle Allan  avatar ximenchuixue avatar yangxiaowei avatar Luan Figueredo avatar Whats in the name avatar yujinpan avatar  avatar Katherine avatar xiaosl avatar  avatar Shashi Kumar Nagulakonda avatar  avatar Shawn avatar Quang Vien (aka Khuc Go) avatar Dashon 'DJ' Hawkins avatar  avatar Maria Kilsved avatar Josh Rickert avatar Egor_Vasilev avatar Dmitriy avatar Nikolay Borzov avatar LLC avatar Björn Klose avatar 王嘉炀 avatar Kevin Kalis avatar  avatar  avatar liyunhua avatar Joabe Mendes avatar Vitalii Doroshenko avatar Mahendran Nadesan avatar 徐胖 avatar Zunzun avatar  avatar Seo Seokjin avatar Dayan Barros avatar Ivan Mrvelj avatar Omar Ben brahim avatar Mel Lota avatar  avatar Anatoly Tarnavsky avatar Jerahmeel Cosinas avatar liushaoqing avatar Krittanan Pingclasai avatar  avatar Hosea Sandstrom avatar  avatar Xandor avatar  avatar cyper avatar Andy Parker avatar Kamil Burek avatar Cristofer Domingues avatar Alberto Roman avatar Lukasz Bandzarewicz avatar Wayne Wang avatar Casey Western avatar Krzysztof Dobrzyński avatar John Ericson avatar 李毅平 avatar wenhao avatar

Watchers

James Cloos avatar Christopher T. Kwiatkowski avatar Maheshchandra Hegde avatar Chris Thielen avatar hack-club avatar Bisham Singh avatar Cool Flame avatar Gregory Tereshko avatar yaser samra avatar Matthew Francis Brunetti avatar

sample-app-angularjs's Issues

Update libraries

Would it be possible to update the libraries to point to the latest versions for the hybrid app? I'm having a few issues doing so

state navigation not happening

Hi all,
There is some issue i am facing in state navigation , i have two module lets say main module and list module.where list module is child of main module and getting loaded lazily.

but when i am trying to change the state from child module to parent module its not happening.
below is the snippet of code i am trying to do.

main module route

const mainState = {
name: "main",
url: "/main",
isLoginRequired: true,
component: "mainComponent"
};
const homeState = {
parent: 'main',
name: "home",
url: '/home',
component: "homeComponent",
isLoginRequired: true,
lazyLoad: ($transition$) => {
return moduleResolver($transition$, () =>
import('../home/home.module'), 'HOME_MODULE');
}
};

const canvasListState = {
parent: 'main',
name: "canvasList.**",
url: '/canvas-list/:projectCode?viewType',
component: "listComponent",
isLoginRequired: true,
lazyLoad: ($transition$) => {
return moduleResolver($transition$, () =>
import('../canvas/list/list.module'), 'LIST_MODULE');
}
};

const drawCanvasState = {
parent: "main",
name: "drawCanvas.**",
url: '/draw-canvas',
lazyLoad: ($transition$) => {
return moduleResolver($transition$, () =>
import('../canvas/draw/draw.module'), 'DRAW_CANVAS_MODULE');
}
};

canvaslist module route
const canvasListState = {
parent: 'main',
name: "canvasList",
url: "/canvas-list/:projectCode?viewType",
params: {
redirecturi: null,
projectCode: null,
viewType: null
},
accessCode: ENUM.ACCESS_CONTROL_LIST.CANVAS_VIEW,
component: "listComponent"
};

now from listComponent if i am saying $state.go('main.drawCanvas.compose').then its not navigating anymore.but if i say $state.go('main') then navigation is getting triggered.

why import all module in bootstrap.js ?

// import "../global/global.module";
// import "../main/main.module";
// import "../contacts/contacts.module";
// import "../mymessages/mymessages.module";
// import "../prefs/prefs.module";

// Google analytics
import '../util/ga';

just import '../util/ga' , the application can also work , and build smaller chunk

Implement redirect on component

Hi i'm triying to implemente the redirectTo mehtod to a state that has a component, but i can't get it working i don't know where does the $transition$.previous(); should come.

this is my state:

.state('app.login', {
    url: '/login',
    views: {
        '[email protected]': {
            templateUrl: getView('login'),
            resolve: { returnTo: returnTo }
        }
    },
})

it never calls the function to resolve.

How to build this one...

I have download the source code, it looks great, very clear. Then I moved it my local nginx/apache , ready for some action but it is not working. I have tried npm install and yarn install but not successful.

Finally "yarn build" is the one.

I know this question is kinda dummy but it would be nice if we have some small guide section for building this sample

'messages' doesn't inject properly

Select app.contacts from the dropdown, then select mymessages

mymessages redirects to mymessages.folder, but then the message: Error: [$injector:unpr] Unknown provider: messagesProvider <- messages appears.

However, clicking directly to mymessages.folder seems to work OK.

demo setup problem

hi! nice Stuff!! thanK yoU !

git clone https://github.com/christopherthielen/new-state-vis.git

npm install && jspm install
     ....
     Looking up npm:typescript
     Looking up npm:ui-router-extras
     Updating registry cache...

err  TypeError: Arguments to path.resolve must be strings
         at Object.posix.resolve (path.js:439:13)

Never used, jspm before - NICE!
0.16.0-beta.7
Running against local jspm install.

Made it work with:

 jspm install github:angular/[email protected]^1.4.7  github:angular-ui/[email protected]^0.2.15 github:mbostock/[email protected]^3.5.6 github:mbostock/d3 npm:[email protected]^1.6.2

Lazy load not visible in networking

It looks like js code related to the contacts module is not fetched just-in-time (on a click to Contacts), as documented.
There's no associated query visible in the networking tab of my browser.
Is that normal ?

Build process fails when attempting to mangle the code base

I'm using webpack's uglifyjs plugin. The code doesn't work if I have the plugins mangle option set to true. I'm getting an injector provider error on build due to the code not being min-safe. I understand why its happening but I can't figure out the necessary steps needed to not make it happen. I'd imagine the primary root cause would be within ngmodule.js where we actually load everything up.

Lazy Load example

Any chance of getting a working lazy load example? the docs are that detailed

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on all branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.

Since we didn’t receive a CI status on the greenkeeper/initial branch, it’s possible that you don’t have CI set up yet. We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.

If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/.

Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please delete the greenkeeper/initial branch in this repository, and then remove and re-add this repository to the Greenkeeper App’s white list on Github. You'll find this list on your repo or organization’s settings page, under Installed GitHub Apps.

Problems with running the app locally on hybrid-angular1-angular2 branch

Could you please revise committed settings?

Steps I take:

  1. $ npm install
  2. $ npm run dev (BTW: inconsistency between branches: dev vs. start in master branch)
  3. Opened http://localhost:3000, got following error:
    Unhandled Promise rejection: (SystemJS) Unable to dynamically transpile ES module as SystemJS.transpiler set to false.
  4. After changing in to true in config.js, I get: Unhandled Promise rejection: (SystemJS) name.lastIndexOf is not a function

If it's my fault and I'm doing sth wrong, perhaps writing a short note on running the stuff in README.md could help.

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on all branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.

Since we didn’t receive a CI status on the greenkeeper/initial branch, it’s possible that you don’t have CI set up yet. We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.

If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/.

Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please delete the greenkeeper/initial branch in this repository, and then remove and re-add this repository to the Greenkeeper App’s white list on Github. You'll find this list on your repo or organization’s settings page, under Installed GitHub Apps.

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.