Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The approach you took in your plunker is close. @ben-schwartz's solution demonstrates how you'd set defaults in your root state for the three essentially-static views. The thing missing in your plunker is that your child states still need to reference the top container view.</p> <pre><code> .state('root',{ url: '', views: { 'header': { templateUrl: 'header.html', controller: 'HeaderCtrl' }, 'footer':{ templateUrl: 'footer.html' } } }) .state('root.about', { url: '/about', views: { 'container@': { templateUrl: 'about.html' } } }); </code></pre> <p>Note <code>views: { 'container@': ...}</code> instead of just <code>templateUrl: ...</code> in <code>'root.about'</code></p> <p>What you may also be asking about is whether you can have modules define their own state-sets, which you then attach to your app's state hierarchy. A sort of plug-and-play for the routes/states each module provides.</p> <p>To achieve this you'll have tightly couple your modules to your main app. </p> <p>In the module:</p> <pre><code>angular.module('contact', ['ui.router']) .constant('statesContact', [ { name: 'root.contact', options: { url: 'contact', views: { 'container@': { templateUrl: 'contacts.html' } }, controller:'ContactController' }} ]) .config(['$stateProvider', function($stateProvider){ }]) </code></pre> <p>Then, in the app:</p> <pre><code>var app = angular.module('plunker', ['ui.router', 'contact']); app.config( ['$stateProvider', 'statesContact', function($stateProvider, statesContact){ $stateProvider .state('root',{ ... }) .state('root.home', { ... }) .state('root.about', { ... }) angular.forEach(statesContact, function(state) { $stateProvider.state(state.name, state.options); }) }]); </code></pre> <p>This means all your modules will need to be compatible with this pattern set out in your app. But if you accept this constraint you can then choose include any combination of your modules, and their states <em>magically</em> get added to your app. If you want to get even fancier, you can modify <code>state.options.url</code> in your <code>statesModuleName</code> loop to, for example, prefix your module's url structure.</p> <p>Also note that the module <code>ui.compat</code> is only necessary when you are <em>transitioning</em> from <code>$routeProvider</code> to <code>$stateProvider</code>. You should normally use <code>ui.state</code> instead.</p> <p>Also don't forget to adjust in header.html <code>$state.includes('root.contact')</code>)</p> <p><a href="http://plnkr.co/edit/OJ5iCSioIUpz6OGYHQG8?p=preview" rel="noreferrer">updated plunker</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload