1

I want to take advantage of ui-routers parent/child states with the demo below. The app appears to be running fine (no console errors), however the html will not render, and the controller's init function isn't firing either. Brand new to this technique, not sure what's wrong with the configuration. Removing the abstract state and configuring the app as normal causes the "Hello World" text to appear.

Plunker

config.js

(function() {
'use strict'
var app = angular.module('app.core');
app.config(AppRouter);
AppRouter.$inject = ['$stateProvider', '$urlRouterProvider'];

function AppRouter($stateProvider, $urlRouterProvider) {
  $urlRouterProvider.otherwise('/login');
  $stateProvider
    .state('main', {
        url: '',
        abstract: true
    })
    .state('main.login', {
      url: '/login',
      templateUrl: 'login.html',
      controller: 'LoginController',
      controllerAs: 'vm',
    });
}
})();

index.html

<body ng-app="app">
<div ui-view=""></div>
<script src="app.module.js"></script>
<script src="app.route.js"></script>
<script src="core.module.js"></script>
<script src="config.js"></script>
<script src="login.module.js"></script>
<script src="login.controller.js"></script>
</body>

login.html

<p>Hello World!</p>

login.controller.js

  (function() {
  'use strict';

  var app = angular.module('app.login');

  app.controller('LoginController', LoginController);

  LoginController.$inject = ['$location', '$filter', '$window', '$rootScope'];

  function LoginController($location, $filter, $window, $rootScope) {
      var init = function(){
          console.log('here');
      };

      init();
  }
  })();

1 Answer 1

1

Each nested state needs a <ui-view> in it's parent template to load into.

Just change your abstract state from:

.state('main', {
        url: '',
        abstract: true
})

To:

.state('main', {
        url: '',
        template:'<ui-view>',
        abstract: true
})

This template could of course be more advanced and also use templateUrl

Sign up to request clarification or add additional context in comments.

1 Comment

Additionally, a nested state can load in any ui-view by using named views github.com/angular-ui/ui-router/wiki/Multiple-Named-Views

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.