angularjs - Modular Angular app using Angular UI Router and Browserify -



angularjs - Modular Angular app using Angular UI Router and Browserify -

i've never used angular ui router before want build application has nested views looks sensible choice. however. can't head around it. application modular have element on page want other modules, view templates, load into.

then when action taken within 1 of nested views, button click, state alter module becomes 1 within main view, , url change:

i'm writing in coffeescript , using browserify tie app together, modules in separate files , required in. i've got far it's not working , can't figure out.

app.coffee

require... require... require... app = angular.module("darrylsnow", [ "nganimate" "ui.router" "submodule1" "submodule2" "templates" ]).config [ "$stateprovider" "$urlrouterprovider" "$locationprovider" ($stateprovider, $urlrouterprovider, $locationprovider) -> $urlrouterprovider .otherwise "/" $stateprovider .state "main", abstract: true # because main module requires submodules url: "/" $locationprovider.html5mode true ]

submodule1.coffee

submodule1 = angular.module("submodule1", [ "ui.router" ]).config [ "$stateprovider" "$urlrouterprovider" "$routeprovider" ($stateprovider, $urlrouterprovider, $routeprovider) -> $stateprovider .state "main.submodule1", url: "" templateurl: "submodule1.html" .state "main.submodule1-expanded", url: "/submodule1" # template shouldn't alter ]

submodule2.coffee

submodule2 = angular.module("submodule2", [ "ui.router" ]).config [ "$stateprovider" "$urlrouterprovider" "$routeprovider" ($stateprovider, $urlrouterprovider, $routeprovider) -> $stateprovider .state "main.submodule2", url: "" templateurl: "submodule2.html" .state "main.submodule2-expanded", url: "/submodule2" # template shouldn't alter ]

is possible have kid states in different modules? if not how recommend it? thanks.

there working example, tried show how set angular, ui-router , coffee together. while not 100% sure trying accomplish ... can find answers , inspiration there.

firstly (simplified) index.html

<head> ... <script src="app.js"></script> <script src="submodule1.js"></script> <script src="submodule2.js"></script> </head> <body> <ul> <a ui-sref="main.submodule1.expanded">main.submodule1.expanded</a> <a ui-sref="main.submodule2({id:22})">main.submodule2</a> <a ui-sref="main.submodule2-expanded({id:22})">main.submodule2-expanded</a> <div ui-view=""></div> </body>

now, app.coffee, of import part template. allow each kid inject view unnamed view template. other alternative utilize absolutely named views, keeps simple:

app = angular.module("darrylsnow", [ "ui.router" "submodule1" "submodule2" ]).config [ "$stateprovider" "$urlrouterprovider" "$locationprovider" ($stateprovider, $urlrouterprovider, $locationprovider) -> $stateprovider .state "main", template: "<div ui-view />" abstract: true # because main module requires submodules url: "/" ...

the other files represents different modules.

the illustration of submodule1.coffeee shows here using nesting (the main.submodule1.expanded kid of main.submodule1):

submodule1 = angular.module("submodule1", [ "ui.router" ]).config [ "$stateprovider" "$urlrouterprovider" "$locationprovider" ($stateprovider, $urlrouterprovider, $locationprovider) -> $stateprovider .state "main.submodule1", template: "<div ui-view />" abstract: true .state "main.submodule1.expanded", url: "/submodule1" # template shouldn't alter templateurl: "submodule1.html" controller: 'some1ctrl' ] submodule1.controller 'some1ctrl', [ "$scope" "$stateparams" "$state" ($scope, $stateparams, $state) -> $scope.params = $stateparams; $scope.state = $state.current; ]

as different approach can utilize siblings submodule2.coffee shows:

submodule2 = angular.module("submodule2", [ "ui.router" ]).config [ "$stateprovider" "$urlrouterprovider" "$locationprovider" ($stateprovider, $urlrouterprovider, $locationprovider) -> $stateprovider .state "main.submodule2", templateurl: "submodule2.html" controller: 'some2ctrl' .state "main.submodule2-expanded", url: "/submodule2/{id}" # template shouldn't alter templateurl: "submodule2.html" controller: 'some2ctrl' ...

well how fits best observe in plunker

angularjs angular-ui-router browserify

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -