传递数据而不添加到url

时间:2019-04-26 05:56:38

标签: angularjs angular-ui-router

$stateProvider.state('academicYearCatalogue', {
    url: '/academicYearCatalogue/:programKey',
    templateUrl: 'app-ace/academicYearCatalogue/views/academicYearCatalogue-detail.tpl.html',
    controller: 'AcademicYearCatalogueDetailCtrl as AcademicYearCatalogueDetailCtrlVM',
    resolve: {
        academicYearList: ['AcademicYearService', '$stateParams',
          function (AcademicYearService, $stateParams) {
            var obj = {
                programKey: $stateParams.programKey,
            }

            return AcademicYearService.getAllYear(obj)
            .$promise.then(function (result) {
                return result.data;
            });

        }]
    }
});

我想通过ui-router v 0.2.8在控制器之间传递数据,但又不想添加到url,我该如何实现呢?
          该programkey来自某个控制器,我想在解析中使用它,但不与url一起使用。我如何实现此目的。

角度js版本为1.2.20

1 个答案:

答案 0 :(得分:0)

使用状态的 params 属性,您可以按以下方式传递数据

参数:{         user_desisred_pa​​rams_name:空, }

因此,下面提供了完整的代码-

$ stateProvider.state('academicYearCatalogue',
   {url:'/ academicYearCatalogue',
        templateUrl:“ app-ace / academicYearCatalogue / views / academicYearCatalogue-detail.tpl.html”,
    控制器:“ AcademicYearCatalogueDetailCtrl as AcademicYearCatalogueDetailCtrlVM”,
    解决:{

    academicYearList: ['AcademicYearService', '$stateParams',
      function (AcademicYearService, $stateParams) {
        var obj = {
            programKey: $stateParams.programKey,
        }

        return AcademicYearService.getAllYear(obj)
        .$promise.then(function (result) {
            return result.data;
        });

    }]
},

参数:{        yourKey:程序密钥    }

});