Javascript angularjs ui路由器嵌套状态新控制器不工作
我被ui路由器中的嵌套状态所困扰。 我正在呈现一个包含每个国家的地区、国家和人员的页面 index.html有三个区域,分别为link、EMEA、APAC和AMER 索引页的部分具有:Javascript angularjs ui路由器嵌套状态新控制器不工作,javascript,php,angularjs,angular-ui-router,Javascript,Php,Angularjs,Angular Ui Router,我被ui路由器中的嵌套状态所困扰。 我正在呈现一个包含每个国家的地区、国家和人员的页面 index.html有三个区域,分别为link、EMEA、APAC和AMER 索引页的部分具有: <a ui-sref="territory({territory: 'amer'})">AMER</a> <a ui-sref="territory({territory: 'emea'})">EMEA</a>
<a ui-sref="territory({territory: 'amer'})">AMER</a> <a ui-sref="territory({territory: 'emea'})">EMEA</a> <a ui-sref="territory({territory: 'apac'})">APAC</a>
<ui-view></ui-view>
支持控制器正在写入一个console.log条目…但什么也没发生。
控制器:
supportApp.controller('countryController',['$scope', 'supportService', '$location', '$stateParams', function($scope, supportService, $location, $stateParams){
$scope.fromTerritory = $stateParams.territory;
$scope.getCountries = function(){
var countries = supportService.getCountries($scope.fromTerritory);
countries.then(function(response){
if(response.data.error){
$scope.error = true;
$scope.message = response.data.message;
}
else{
console.log('response OK');
$scope.region = $scope.fromTerritory;
$scope.countries = response.data;
}
});
}
$scope.getCountries();
}]);
supportApp.controller('supportController',['$scope', 'supportService', '$location', '$stateParams', function($scope, supportService, $location, $stateParams){
console.log('in the supportController');
var test = function(){
console.log('supportController country: '+$stateParams.country);
}
test();
}]);
我可能做错了什么。
目标是单击国家,然后显示属于该特定国家的人员的姓名
如果不清楚,我可以在需要的地方提供更多信息。但目前看来,嵌套状态(.territory.support)的控制器(supportController)没有运行/加载
谢谢大家! 好的,
我现在有我的答案。。。
因为我没有在supporter.html上使用
,所以控制器不“需要”,也没有加载。
添加后,consol.log将显示日志条目
$urlRouterProvider.otherwise('/home');
$stateProvider
.state('home', {
url: '/home',
templateUrl: 'views/home.html',
controller: 'supportCtrl'
})
.state('territory', {
url: '/territory/:territory',
templateUrl: 'views/countries.html',
controller: 'countryController'
})
.state('territory.support',{
url: '/:country',
templateUrl: 'views/supporter.html',
controller: 'supportController'
})
});
supportApp.controller('countryController',['$scope', 'supportService', '$location', '$stateParams', function($scope, supportService, $location, $stateParams){
$scope.fromTerritory = $stateParams.territory;
$scope.getCountries = function(){
var countries = supportService.getCountries($scope.fromTerritory);
countries.then(function(response){
if(response.data.error){
$scope.error = true;
$scope.message = response.data.message;
}
else{
console.log('response OK');
$scope.region = $scope.fromTerritory;
$scope.countries = response.data;
}
});
}
$scope.getCountries();
}]);
supportApp.controller('supportController',['$scope', 'supportService', '$location', '$stateParams', function($scope, supportService, $location, $stateParams){
console.log('in the supportController');
var test = function(){
console.log('supportController country: '+$stateParams.country);
}
test();
}]);