I've never used Angular UI Router before but I want to build an application that has nested views so it looks like the most sensible choice. However. I just can't get my head around it. My application is modular so I have an element on my page that I want the other modules, with their view templates, to load into.
Then when some action is taken inside one of the nested views, say a button click, I would like the state to change so that module to becomes the only one inside the main view, and for the URL to change:
I'm writing in CoffeeScript and using Browserify to tie the app together, so all the modules are in separate files and required in. This is where I've got so far but it's not working and I can't figure it 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 the main module requires the 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 change
]
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 change
]
Is it even possible to have child states in different modules? If not how would you recommend I do it? Thanks.