Angular Routing将控制器传递到路由的子项

Angular Routing pass the controller to subitem of route

本文关键字:路由 Routing 控制器 Angular      更新时间:2023-09-26

你好,我如何将相同的控制器传递到其他窗口中加载的主状态的子状态?

.state('Project',{
    url:'/Project:projectId',
    views:{
        'mainContent':{
            templateUrl:'templates/view/project.html',
    controller:'ProjectCtrl'
        }
    }
}).state('Project.whoiscustomer',{
    url:'/whoiscustomer',
    views:{
        'rightContent':{
            templateUrl:'templates/projectMembers/whoiscustomer.html',
    controller:'ProjectCtrl'
        }
}

有人能解释一下吗?

或者如何改变这是项目视图属性?

ng-href="#/Project:projectId/whoiscustomer"

有几千种简单的离子观点。。。

.state('Project',{
    url:'/Project/:projectId',
    templateUrl:'templates/view/project.html',
    controller:'ProjectCtrl'
})
.state('Project.whoiscustomer',{
    url:'/whoiscustomer',
    templateUrl:'templates/projectMembers/whoiscustomer.html'
})

如果只有一个视图,则不必命名视图,只需在模板中使用<div ui-view></div>即可。

.state('Project',{
url:'/Project:projectId',
views:{
    'mainContent':{
        templateUrl:'templates/view/project.html',
controller:'ProjectCtrl'
    }
}

添加摘要:true,

使技巧

.state('Project',{
abstract: true,
url:'/Project:projectId',
views:{
    'mainContent':{
        templateUrl:'templates/view/project.html',
controller:'ProjectCtrl'
    }
}