I am using ui-router and have 2 tabs under a page which can be navigated via navigation bar (Home || Logs || Quick Info).
On clicking Logs, I have 2 tabs (Tab1 and Tab2). I have separate controllers for each tab and a main controller for a Log Page.
On clicking the Log Page MainCtrl gets executed once. Tab1 gets activated and the Tab1Ctrl gets executed twice..the same with Tab2.
Here is the code: Route.js
'use strict';
/**
* Routing for Scheduler PreProcessor Application
*/
schedulerPreProcessor.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('home', {
url : '/home',
templateUrl : 'schedulerPreProcessor/models/scheduler/home.html',
controller : 'mainController'
})
.state('logs', {
url : '/logs',
templateUrl : 'schedulerPreProcessor/models/logs/logs.html',
controller : 'logsController',
resolve : {
'currentLogData' : function($stateParams, SchedulerHTTPService) {
return SchedulerHTTPService.getCurrentLogLevel();
}
}
})
.state('logs.logInfo', {
url : 'logs/logInfo',
templateUrl : 'schedulerPreProcessor/models/logs/logInfo/logInfo.html',
controller : 'logInfoController'
})
.state('logs.appProperties', {
url : 'logs/appProperties',
templateUrl : 'schedulerPreProcessor/models/logs/appProperties/appProperties.html',
controller : 'appPropertiesController'
})
.state('info', {
url : '/info',
templateUrl : 'schedulerPreProcessor/models/quick_info/info.html',
controller : 'quickInfoController'
});
$urlRouterProvider.otherwise('/home');
});
logs.html
<div ng-init="onLoad();">
<tabset>
<tab ng-repeat="tab in tabs" select="go(tab.route)"
ui-sref-active="tab.active" heading="{{tab.title}}"
active="tab.active" disable="tab.disabled">
<ui-view></ui-view>
</tab>
</tabset>
</div>
Logs controller
'use strict';
schedulerPreProcessor.controller('logsController', function($scope, $filter,
$http, $state, $stateParams, $rootScope, $location,
SchedulerHTTPService, referenceDataService, currentLogData) {
/**
* Navigation of Tabs.
*/
$scope.go = function(route) {
$state.go(route);
};
$scope.name="Hello";
$scope.onLoad = function(){
/**
* tabs
*/
$scope.tabs = [ {
title : 'Log Info',
route : 'logs.logInfo'
}, {
title : 'Application Properties',
route : 'logs.appProperties'
} ];
/**
* logs
*/
$scope.logs = [ {
key : 'log01',
value : 'root',
name : 'Application Log',
isChecked : false
}, {
key : 'log02',
value : 'org.hibernate',
name : 'Hibernate Log',
isChecked : false
}, {
key : 'log03',
value : 'org.springframework',
name : 'Spring Log',
isChecked : false
} ];
/**
* dataLogList
*/
$scope.dataLogList = [ {
key : 'log01',
value : 'appLog',
name : 'Application Log'
}, {
key : 'log02',
value : 'hibLog',
name : 'Hibernate Log'
}, {
key : 'log03',
value : 'springLog',
name : 'Spring Log'
}, {
key : 'log04',
value : 'perfLog',
name : 'Performance Log'
} ];
$scope.logTypeList = [];
if ($scope.logTypeList.length == 0 && referenceDataService != null
&& referenceDataService.loadRefData() != null) {
$scope.logTypeList = referenceDataService.loadRefData().logRefData;
}
$scope.effectiveLogLevel = null;
$scope.isHideCurrentLogLevelSection = true;
if (currentLogData != null && currentLogData.currentLogLevel != null) {
$scope.isHideCurrentLogLevelSection = false;
$scope.effectiveLogLevel = currentLogData.currentLogLevel;
}
$scope.sectionTitle = null;
$scope.hideLogSection = true;
$scope.HTTPRequestMessage = {};
$scope.HTTPResponseMessage = {};
$scope.isDisableLogApplyButton = true;
$scope.isDisableLogResetButton = true;
};
});
LogInfoController.js
'use strict';
schedulerPreProcessor.controller('logInfoController', function($scope, $filter,
$http, $state, $stateParams, $rootScope, $location,
SchedulerHTTPService, referenceDataService, currentLogData) {
$scope.name="Hello";
});
appPropertiesController.js
'use strict';
schedulerPreProcessor.controller('appPropertiesController', function($scope, $filter,
$http, $state, $stateParams, $rootScope, $location,
SchedulerHTTPService, referenceDataService, currentLogData) {
$scope.lastName="XXXXXXXXX";
});
The other 2 controllers are plain and simple...just div tags and plain functions in controllers for populating DOM elements.
Any Help would be great.
Trying to figure out what is wrong in having separate controllers for separate tabs.
Thanks in advance.