环境:
angularJS(1.6.4),要跳转的页面是后台处理好放到放到返回的data(JSON格式)数据里,$stateProvider根据返回的数据动态跳不同页面
commonController.js
(function() {
var injectParams = ['$location', '$scope', '$state', '$stateParams', '$timeout', '$uibModal', 'uiGridConstants', 'DownloadService', 'HistoryManagerService', 'OptionsService', 'ModalService', 'ModelService', 'NIS', 'NisGridUtil', 'ScopeSetupService', 'AuthorityService', 'SproSeisanUtil', 'MasterMenteService', 'input']; // <- SrcScriptによる生成
var newController = function ($location, $scope, $state, $stateParams, $timeout, $uibModal,
uiGridConstants,
DownloadService, HistoryManagerService, OptionsService, ModalService, ModelService, NIS, NisGridUtil, ScopeSetupService, AuthorityService, SproSeisanUtil,
MasterMenteService, input
) {
$scope.input = input;
angular.module('app').nlmcontroller.get($scope.input.modelIdTo.replace(' ','')+'Controller').call( $scope, $location, $scope, $state, $stateParams, $timeout, $uibModal,
uiGridConstants,
DownloadService, HistoryManagerService, OptionsService, ModalService, ModelService, NIS, NisGridUtil, ScopeSetupService, AuthorityService, SproSeisanUtil,
MasterMenteService, input);
$timeout(function() {
NisUtil.nlmCheckAttr(input);
})
};
newController.$inject = injectParams;
angular.module('app').controller('commonController', newController);
})();
State.js
(function () {
// 必要な依存を列挙
var injectParams = ['$stateProvider', 'stateHelperProvider', '$urlRouterProvider'];
// 引数は依存の内容と一致する
var newState = function ($stateProvider, stateHelperProvider, $urlRouterProvider) {
// 必要なステートを記述
// 例
$stateProvider
//这个是普通的绑定
.state('qpZaishitsuMenteMenu', {
url: '/master/qpZaishitsuMenteMenu/:mode',
controller: 'commonController',
templateUrl: 'app/main/master/ICAS757.html',
resolve: {
input(MasterMenteService, $stateParams) {
var para = {
qpZaishitsuShoriKbn: $stateParams.qpZaishitsuShoriKbn,
qpZaishitsuMasterShuruiKbn: $stateParams.qpZaishitsuMasterShuruiKbn,
zfJis: $stateParams.zaishitsu
}
return MasterMenteService.qpZaiShisuMstInit(para).then(data => {
return data;
});
},
},
data: {
gamenContext: {}
},
menu: 'demo',
title: '【QP材質マスターメンテナンス】',
isLoginRequired: true
})
//这个是动态绑定
//controller : function(){return xxx}可绑定为匿名函数返回值
//templateUrl绑定匿名函数的返回值
.state('qpFunc', {
url: '/master/qpFunc/:{inMsgData:json}',
controller:'commonController',
templateUrl:function(){return $stateProvider.nlmTemplateUrl},
resolve: {
input(MasterMenteService, $stateParams, AlertService) {
return MasterMenteService.qpFunc($stateParams.inMsgData).then(data => {
$stateProvider.nlmTemplateUrl = 'app/main/master/' + data.modelIdTo.replace(' ', '') + '.html';
$stateProvider.nlmController = data.modelIdTo.replace(' ', '') + 'Controller';
if (null != data.msgInfo && "" != data.msgInfo) {
AlertService.addInfo(data.msgInfo,5000,'MSG');
}
return data;
});
},
},
menu: 'demo',
title: '【QP材質マスターメンテナンス】',
isLoginRequired: true
})
};
newState.$inject = injectParams;
angular.module('app').config(newState);
}());