I'm using AngularJs UI-Router for my app, but I'm with a problem where the parent's controller isn't initiated.
This is my state structure:
.state('main', { abstract: true, controller: 'MainController', controllerAs: 'vm', resolve: { config: function($timeout){ return $timeout(function() { return console.log('loaded') }, 1000); } } }) .state('home', { parent: 'main', url: '/Home', views: { 'content@': { templateUrl: 'view/home.html' } } }) .state('contact', { parent: 'main', url: '/Contact', views: { 'content@': { templateUrl: 'view/contact.html', } } }) The template home.html and contact.html are displaying on the view just fine. But inside the MainController I have just a console.log but it doesn't appear on the console.
If I make some changes, I can make it work. This is the working example:
.state('main', { abstract: true, views: { 'main': { template: '<div ui-view="content"></div>', controller: 'MainController', controllerAs: 'vm' } } [...code...] .state('home', { parent: 'main', url: '/Home', views: { 'content': { [...code...] This way, everything works as expected, The view appear and the console from the controller also appear.
But it doesn't seem "right" because I need to create a template just to hold the child states.
Is there a way to make it work with the first option?
controllerAstry to usecontroller: MainController as vmcontroller: 'MainController', without the controllerAs, but got the same results.