I'm using ui-router
with nested views to display a few tables with user data on a user profile page. Here is an overview of the routes:
routes.config.js
(function() {
'use strict';
angular.module('app.routes').config(routesConfig);
routesConfig.$inject = ['$stateProvider', '$locationProvider', '$urlRouterProvider', 'RouteHelpersProvider'];
function routesConfig($stateProvider, $locationProvider, $urlRouterProvider, helper){
// Set the following to true to enable the HTML5 Mode
// You may have to set <base> tag in index and a routing configuration in your server
$locationProvider.html5Mode(false);
// defaults to dashboard
$urlRouterProvider.otherwise('/app/home');
//
// Application Routes
// -----------------------------------
$stateProvider
.state('app', {
url: '/app',
abstract: true,
templateUrl: helper.basepath('app.html'),
resolve: helper.resolveFor('fastclick', 'modernizr', 'icons', 'screenfull', 'animo', 'sparklines', 'slimscroll', 'classyloader', 'toaster', 'whirl','loaders.css', 'spinkit','jquery-ui', 'jquery-ui-widgets','weather-icons', 'skycons')
})
.state('app.home', {
url: '/home',
title: 'Home',
templateUrl: helper.basepath('home.html'),
})
.state('app.user', {
abstract: true,
templateUrl: helper.basepath('user.html'),
// controller: 'UserPageController',
// controllerAs: 'userCtrl',
resolve: helper.resolveFor('datatables')
})
.state('app.user.dashboard', {
url: '/user',
title: 'User',
controller: 'UserPageController',
controllerAs: 'userCtrl',
views: {
'eventTable': {
templateUrl: helper.basepath('userProfile/eventTable.html'),
controller: 'EventTableController',
controllerAs: 'eventCtrl'
},
'bankStatement': {
templateUrl: helper.basepath('userProfile/bankStatement.html'),
controller: 'BankStatementController',
controllerAs: 'bankCtrl'
},
'purchasesTable': {
templateUrl: helper.basepath('userProfile/purchasesTable.html'),
controller: 'PurchasesTableController',
controllerAs: 'purchasesCtrl'
},
'paymentsTable': {
templateUrl: helper.basepath('userProfile/paymentsTable.html'),
controller: 'PaymentsTableController',
controllerAs: 'paymentsCtrl'
},
'clicksTable': {
templateUrl: helper.basepath('userProfile/clicksTable.html'),
controller: 'ClicksTableController',
controllerAs: 'clicksCtrl'
},
}
});
} // routesConfig
})();
When I try to add another controller to display the user's basic info(I have tried adding the controller to app.user
and app.user.dashboard
) the controller is never activated. Here is the rest of the relevant code:
user.html
<h3 class="fixedSubHeader">{{userCtrl.userInfo}}</h3>
<section ui-view="eventTable"></section>
<section ui-view="bankStatement"></section>
<section ui-view="paymentsTable"></section>
<section ui-view="purchasesTable"></section>
<section ui-view="clicksTable"></section>
userPage.controller.js
(function() {
'use strict';
angular
.module('app.userPage')
.controller('UserPageController', UserPageController);
UserPageController.$inject = ['$resource'];
function UserPageController($resource) {
var vm = this;
activate();
// console.log("USER!!!!!");
////////////////
function activate() {
// Ajax
$resource('server/basic-info-table.json').query().$promise.then(function(userInfo) {
vm.userInfo = userInfo;
});
}
}
})();
I originally thought this was a problem with the userPage controller so I tried injecting $scope
and getting rid of the var vm = this
syntax. This approach, however, also did not work. Any help would be greatly appreciated. Thanks