我正在使用ui路由器,並在可以通過導航欄(主頁||日誌||快速信息)導航的頁面下有2個選項卡。Angular Js/ui路由器/選項卡設置,控制器被調用兩次
單擊日誌時,我有2個選項卡(Tab1和Tab2)。我有單獨的控制器爲每個選項卡和主頁控制器的日誌頁面。
單擊日誌頁面MainCtrl會執行一次。 Tab1被激活並且Tab1Ctrl被執行兩次。與Tab2相同。
下面是代碼: 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>
日誌控制器
'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";
});
另2個控制器是簡單明瞭...在控制器用於填充DOM元素只是div標籤和滑動功能。
任何幫助將是偉大的。
試圖找出單獨的標籤單獨控制器有什麼問題。
在此先感謝。
你可以爲這個狀態添加狀態還可以查看html嗎? –
@PankajParkar添加狀態和視圖 – MBK