scope and controller instantiation with ui router

To get even more detailed answers, we can/should observe the source code and check the documentation. Let me try to explain all three questions (and also cite from code and doc). 1. When do controllers get instantiated? Here we can observe the code of the ui-view directive: [$ViewDirective.$inject = \[‘$state’, ‘$injector’, ‘$uiViewScroll’, ‘$interpolate’\];][1] Controllers are … Read more

Angularjs ui-router abstract state with resolve

Solution here is to distinguish the names of the resolved data. Check this answer: angular ui-route state parent and resolve (nested resolves) And its plunker So in our case we would need this change in parent resolve: { dataParent: [‘$stateParams’, ‘ProfileService’, function ($stateParams, ProfileService) { var username = $stateParams.username; return ProfileService.getProfile(username); }] } and this … Read more

Prepend optional attribute in angular ui-router URL

It’s probably bad practice to have two separate routes point to the same state, but nothing is keeping you from creating two different states that use the same resolutions/controller/template. $stateProvider .state(‘state1’, { url: “/:city/events/:id”, templateUrl: “partials/events.html”, controller: eventsCtrl }) .state(‘state2’, { url: “/events/:id”, templateUrl: “partials/events.html”, controller: eventsCtrl }); function eventsCtrl($scope){ // shared controller } Again, … Read more

multiple ui-view html files in ui-router

I am not sure if I do understand your goal 100%, but there is updated plunker, showing how we can work with nested views. Firstly, there is a $state defintion showing the nesting: $stateProvider .state(‘index’, { url: “https://stackoverflow.com/”, views: { ‘@’ : { templateUrl: ‘layout.html’, controller: ‘IndexCtrl’ }, ‘top@index’ : { templateUrl: ‘tpl.top.html’,}, ‘left@index’ : … Read more