如何通过state.js传递一个值(我从ui-router得到)到一个模态/视图

How to pass a value (which i got from ui-router) to a modal/view through state.js?

本文关键字:一个 得到 ui-router 模态 视图 我从 何通过 js state      更新时间:2023-09-26

我的状态。Js是这样的

 .state('lab.new-equip', {
            parent: 'lab',
            url: '/{labId}/new-equipment',
            data: {
                authorities: ['ROLE_USER']
            },
            onEnter: ['$stateParams', '$state', '$uibModal', function ($stateParams, $state, $uibModal) {
                $uibModal.open({
                    templateUrl: 'app/entities/lab/lab-equipments-dialog.html',
                    controller: 'LabEquipmentsDialogController',
                    controllerAs: 'vm',
                    backdrop: 'static',
                    size: 'lg',
                    resolve: {
                        entity: function () {
                            return {
                                roomId: $stateParams.labId,
                                equipementName: null,
                                specification: null,
                                manufacturer: null,
                                quantity: null,
                                author: null,
                                id: null
                            }.$promise;
                        }
                    }
                }).result.then(function () {
                    $state.go('lab', null, {reload: true});
                }, function () {
                    $state.go('lab');
                });
            }]
        })

我已经使用ui-router获得了labId的值,如下所示

  ui-sref="lab.new-equip({labId:vm.lab.labId})"

现在我试图将这个labId作为roomId的值传递给视图。因此,我尝试在$stateParams的帮助下发送。

但是我无法在我的模态中填充值。

如果我将roomId更改为2或3之类的整数,则它正在填充模态。但不是以前的方式。

我怎样才能做到这一点?

还有其他方法可以完成这个吗?

Thanks in advance

试试下面的代码:

function ($stateParams, $state, $uibModal) {
        $uibModal.open({
            templateUrl: 'app/entities/lab/lab-equipments-dialog.html',
            backdrop: 'static',
            size: 'lg',
            resolve: {
                selectedRow: function () {                    
                    return row.entity.labId;
                }
            },
            controller: function ($scope, $uibModal, selectedRow) {
                $scope.selectedRow = selectedRow;
                $stateParams.labId = $scope.labId;
            }
        }).result.then(function () {
            $state.go('lab', null, {reload: true});
        }, function () {
            $state.go('lab');
        });

只需添加如下内容

resolve: {
                    entity: function () {
                        return {
                            roomId: null,
                            equipementName: null,
                            specification: null,
                            manufacturer: null,
                            quantity: null,
                            author: null,
                            id: null
                        }.$promise;
                    }
                    roomId: function (){
                    return $stateParams.id;
                    }

并在控制器中注入roomId以在html页面中使用它。

相关文章: