我正在使用UI-Router导航到详细视图。它正确更改状态并正确传递参数,但浏览器中的URL地址保持不变。我想显示在URL中传递的参数。Angularjs UI路由器更改状态,但通过参数时不更新网址
app.js
'use strict';
var myApp = angular.module("myApp", ['ui.router']);
myApp.config(['$stateProvider', '$urlRouterProvider','$locationProvider',
function($stateProvider, $urlRouterProvider,$locationProvider) {
$urlRouterProvider.otherwise('/');
$stateProvider
.state('/', {
url: '/',
templateUrl: 'partials/listView.html'
})
.state('list', {
url: '/',
templateUrl: 'partials/listView.html'
})
.state('detail', {
url: '/detail/:key',
params: {
key: { value: "" }
},
templateUrl: 'partials/detailView.html',
controller: 'DetailController'
})
// use the HTML5 History API
$locationProvider.html5Mode(true);
}]);
控制器功能去详细状态:
myApp.controller('MainContr', [ '$scope', '$http', '$location', '$state',
'$filter','$rootScope', MainContr ]);
function MainContr($scope, $http, $location, $state, $filter,$rootScope) {
$scope.goDetailView= function(key){
console.log("trying to change url ");
// changes state correctly, and passes params to DetailController,
// but does not change browser address url.
// How can I update the url in browser here?
$state.go('detail',
{key: $scope.selectedPDFKey},
{
location:true
});
}
}
// detail view
myApp.controller('DetailController', [ '$scope', '$stateParams'
DetailController ]);
function PDFDetailController($scope,$state)
{
$scope.currentKey=$state.params.key;
}
如果我删除$state.go('detail')
params
,在浏览器地址栏中的URL将被替换。当我在$ state.go()中传递参数时,如何替换浏览器地址栏中的url?谢谢。
我没有使用''。我需要对'ng-click'单独行动(将点击的行设置为活动状态)和'ng-dblclick'(将视图更改为详细视图)。例如: ' ' –
kaplievabell
我不确定是否我明白什么是问题。但是,我在这里试着http://plnkr.co/edit/WIrNyAQjM771335Wzx4w?p=preview跟随您的评论1)它是我们与双击会触发你的行动链接列表上工作2)3)详情具有BACK行动,导航我们回到列表..它有帮助吗?一点点? –
问题是它不会将浏览器地址url更改为'http:// myaddress/detail/product1'。地址保留为'http:// myaddress'我需要将地址url分享给特定产品的功能。 – kaplievabell