AngularJS:来自不同模块的嵌套命名视图

AngularJS:来自不同模块的嵌套命名视图,angularjs,angular-ui-router,nested-views,Angularjs,Angular Ui Router,Nested Views,我正在使用angular ui router加载嵌套的命名视图 在index.html文件中,我有一个未命名视图和一个命名视图 Index.html: <div ui-view="header"></div> <div ui-view=""></div> 我使用三个模块:myApp、国家/地区和联系人。我已经为每个模块配置了路由 MyApp模块: angular.module('myApp', ['ui.state', 'conta

我正在使用angular ui router加载嵌套的命名视图

在index.html文件中,我有一个未命名视图和一个命名视图

Index.html:

<div ui-view="header"></div>       
<div ui-view=""></div>
我使用三个模块:myApp国家/地区和联系人。我已经为每个模块配置了路由

MyApp模块:

angular.module('myApp', ['ui.state', 'contacts', 'countries'])
.config(['$stateProvider', '$routeProvider',  
    function ($stateProvider, $routeProvider) {
    $stateProvider
        .state("home",
        {
            url: "/home",
            abstract: true,
            views: {
                'header': {
                    template: "<div class ='row' ui-view ='countriesList'></div><div class ='row' ui-view ='contactsSearch'></div>"
                },
                "": {
                    template: "<div ui-view></div>"
                }
            }
        }); 

    }]);
angular.module('countries', ['ui.state'])
.config(['$stateProvider', '$routeProvider',  
    function ($stateProvider, $routeProvider) {
    $stateProvider
        .state("home.countries", {
            url: "/countries",
            views: {
                'countriesList': {
                    template: "<p>Countries</p>"
                }
            }
        });

    }])
    .run(['$rootScope', '$state', '$stateParams', function ($rootScope,   $state, $stateParams) {
        $rootScope.$state = $state;
        $rootScope.$stateParams = $stateParams;
        $state.transitionTo('home.countries');
    }]);
angular.module('contacts', ['ui.state'])
.config(['$stateProvider', '$routeProvider',  
    function ($stateProvider, $routeProvider) {
    $stateProvider
        .state("home.contacts", {//should be loaded to the unnamed view in index.html
            url: "",
            views: {
                'contactsList': {
                    template: "<p>Contacts List</p>"
                }
            }
        })
        .state("home.contactsSearch", {
            url: "/contactsSearch",
            views: {
                'contactsSearch': {
                    template: "<p>Contacts Search</p>"
                }
            }
        });

    }])
    .run(['$rootScope', '$state', '$stateParams', function ($rootScope,   $state, $stateParams) {
        $rootScope.$state = $state;
        $rootScope.$stateParams = $stateParams;
        $state.transitionTo('home.contactsSearch');
    }]);
angular.module('myApp',['ui.state','contacts','countries']))
.config(['$stateProvider','$routeProvider',
函数($stateProvider,$routeProvider){
$stateProvider
.州(“家”,
{
网址:“/home”,
摘要:没错,
观点:{
“标题”:{
模板:“”
},
"": {
模板:“”
}
}
}); 
}]);
国家/地区模块:

angular.module('myApp', ['ui.state', 'contacts', 'countries'])
.config(['$stateProvider', '$routeProvider',  
    function ($stateProvider, $routeProvider) {
    $stateProvider
        .state("home",
        {
            url: "/home",
            abstract: true,
            views: {
                'header': {
                    template: "<div class ='row' ui-view ='countriesList'></div><div class ='row' ui-view ='contactsSearch'></div>"
                },
                "": {
                    template: "<div ui-view></div>"
                }
            }
        }); 

    }]);
angular.module('countries', ['ui.state'])
.config(['$stateProvider', '$routeProvider',  
    function ($stateProvider, $routeProvider) {
    $stateProvider
        .state("home.countries", {
            url: "/countries",
            views: {
                'countriesList': {
                    template: "<p>Countries</p>"
                }
            }
        });

    }])
    .run(['$rootScope', '$state', '$stateParams', function ($rootScope,   $state, $stateParams) {
        $rootScope.$state = $state;
        $rootScope.$stateParams = $stateParams;
        $state.transitionTo('home.countries');
    }]);
angular.module('contacts', ['ui.state'])
.config(['$stateProvider', '$routeProvider',  
    function ($stateProvider, $routeProvider) {
    $stateProvider
        .state("home.contacts", {//should be loaded to the unnamed view in index.html
            url: "",
            views: {
                'contactsList': {
                    template: "<p>Contacts List</p>"
                }
            }
        })
        .state("home.contactsSearch", {
            url: "/contactsSearch",
            views: {
                'contactsSearch': {
                    template: "<p>Contacts Search</p>"
                }
            }
        });

    }])
    .run(['$rootScope', '$state', '$stateParams', function ($rootScope,   $state, $stateParams) {
        $rootScope.$state = $state;
        $rootScope.$stateParams = $stateParams;
        $state.transitionTo('home.contactsSearch');
    }]);
angular.module('countries',['ui.state']))
.config(['$stateProvider','$routeProvider',
函数($stateProvider,$routeProvider){
$stateProvider
.state(“home.countries”{
网址:“/国家”,
观点:{
“国家名单”:{
模板:“国家

” } } }); }]) .run(['$rootScope','$state','$stateparms',函数($rootScope,$state,$stateparms){ $rootScope.$state=$state; $rootScope.$stateParams=$stateParams; $state.transitiono('home.countries'); }]);
联系人模块:

angular.module('myApp', ['ui.state', 'contacts', 'countries'])
.config(['$stateProvider', '$routeProvider',  
    function ($stateProvider, $routeProvider) {
    $stateProvider
        .state("home",
        {
            url: "/home",
            abstract: true,
            views: {
                'header': {
                    template: "<div class ='row' ui-view ='countriesList'></div><div class ='row' ui-view ='contactsSearch'></div>"
                },
                "": {
                    template: "<div ui-view></div>"
                }
            }
        }); 

    }]);
angular.module('countries', ['ui.state'])
.config(['$stateProvider', '$routeProvider',  
    function ($stateProvider, $routeProvider) {
    $stateProvider
        .state("home.countries", {
            url: "/countries",
            views: {
                'countriesList': {
                    template: "<p>Countries</p>"
                }
            }
        });

    }])
    .run(['$rootScope', '$state', '$stateParams', function ($rootScope,   $state, $stateParams) {
        $rootScope.$state = $state;
        $rootScope.$stateParams = $stateParams;
        $state.transitionTo('home.countries');
    }]);
angular.module('contacts', ['ui.state'])
.config(['$stateProvider', '$routeProvider',  
    function ($stateProvider, $routeProvider) {
    $stateProvider
        .state("home.contacts", {//should be loaded to the unnamed view in index.html
            url: "",
            views: {
                'contactsList': {
                    template: "<p>Contacts List</p>"
                }
            }
        })
        .state("home.contactsSearch", {
            url: "/contactsSearch",
            views: {
                'contactsSearch': {
                    template: "<p>Contacts Search</p>"
                }
            }
        });

    }])
    .run(['$rootScope', '$state', '$stateParams', function ($rootScope,   $state, $stateParams) {
        $rootScope.$state = $state;
        $rootScope.$stateParams = $stateParams;
        $state.transitionTo('home.contactsSearch');
    }]);
angular.module('contacts',['ui.state']))
.config(['$stateProvider','$routeProvider',
函数($stateProvider,$routeProvider){
$stateProvider
.state(“home.contacts”,{//应加载到index.html中的未命名视图
url:“”,
观点:{
“联系人列表”:{
模板:“联系人列表”
}
}
})
.state(“home.contacts搜索”{
url:“/contactsSearch”,
观点:{
“联系人搜索”:{
模板:“联系人搜索”
}
}
});
}])
.run(['$rootScope','$state','$stateparms',函数($rootScope,$state,$stateparms){
$rootScope.$state=$state;
$rootScope.$stateParams=$stateParams;
$state.transitiono('home.contactsSearch');
}]);
我的代码不正确,因为没有显示任何内容,我无法找出原因。经过一些调查,我发现父母只能有一种状态,但我需要家。联系人家。联系人搜索家。国家要有相同的父母:

有人能帮我吗

我创建了一个JSFIDLE以了解更多细节:


谢谢

有什么理由需要单独的模块吗?我分叉并清理了你的小提琴,让它工作并显示标题视图:Thank you@officert,但我想使用模块化,因为我正在处理的应用程序将是一个大型应用程序,我想按功能而不是类型来组织它。我也能让它像你那样工作,但问题是当我有多个模块时,每个模块都有自己的配置文件。你在这方面运气好吗?我刚刚遇到了同样的问题。有没有理由要有单独的模块?我分叉并清理了你的小提琴,让它工作并显示标题视图:Thank you@officert,但我想使用模块化,因为我正在处理的应用程序将是一个大型应用程序,我想按功能而不是类型来组织它。我也能让它像你那样工作,但问题是当我有多个模块时,每个模块都有自己的配置文件。你在这方面运气好吗?我刚刚碰到了同样的问题。