当我重新加载页面时,state.params将变为空

时间:2016-02-16 04:31:25

标签: angularjs angular-ui-router

我在我的应用程序中使用ui-routing并且工作非常好但现在我根据$ state.params在页面上显示内容,当我来自该页面上的其他链接时,state.params即将到来作为我们的要求,但当我重新加载此页面时,$ state.params将变为空。

路由:

intakeApp.config(['$stateProvider', '$urlRouterProvider', '$locationProvider',
function ($stateProvider, $urlRouterProvider, $locationProvider) {
$urlRouterProvider.otherwise('/intake');
$stateProvider.state('data', {
url: '/data',
controller: 'dataController',
templateUrl: 'data.html',
}).state('data.media', {
url: '?matterId',
templateUrl: 'media.html'
})
$locationProvider.html5Mode(true);
}]);

打开页面的链接: 链接到打开主页:

<a ui-sref="data" ui-sref-opts="{reload: true, notify: true}">Data</a

链接以打开主页上的内容:

function onClickRow(matterId) {
$state.go('data.media', { matterId: matterId }, { redirect: true });
}

控制器:

intakeApp.controller('dataController', ['$http', '$scope', 'intakeAppFactory', 'DTOptionsBuilder', 'DTColumnDefBuilder', '$uibModal', '$filter', '$timeout', '$compile', '$state', '$stateParams', function PostController($http, $scope, intakeAppFactory, DTOptionsBuilder, DTColumnDefBuilder, $uibModal, $filter, $timeout, $compile, $state, $stateParams) {
$scope.state = $state.current;
$scope.params = $state.params;
if (($scope.params.matterId == undefined) && ($scope.params.mediaId == undefined)) {
$scope.showMatterTable();
}
if (($scope.params.matterId != undefined) && ($scope.params.mediaId == undefined)) {
$scope.showMediaTable();
}
if (($scope.params.matterId != undefined) && ($scope.params.mediaId != undefined)) {
$scope.showDatasetTable();
}

主要网址: http://localhost:62814/data 内容页面网址在主页: http://localhost:62814/data?matterId=000001-000001

0 个答案:

没有答案