我有一个组件,我需要检测用户是否在他的浏览器中按下了按钮以导航回来.
目前我正在订阅路由器事件.
constructor(private router: Router, private activatedRoute: ActivatedRoute) {
this.routerSubscription = router.events
.subscribe(event => {
// if (event.navigatesBack()) ...
});
}
Run Code Online (Sandbox Code Playgroud)
我知道我可以使用,window.onpopstate但在使用Angular2时感觉就像是黑客.
我正在使用Angular 2开发一个网站.有没有办法使用Angular 2禁用或触发浏览器后退按钮?
谢谢
我有一个示例ui-bootstrap模式(来自ui-bootstrap文档)
angular.module('ui.bootstrap.demo', ['ui.bootstrap']);
angular.module('ui.bootstrap.demo').controller('ModalDemoCtrl', function ($scope, $modal, $log) {
$scope.items = ['item1', 'item2', 'item3'];
$scope.animationsEnabled = true;
$scope.open = function (size) {
var modalInstance = $modal.open({
animation: $scope.animationsEnabled,
templateUrl: 'myModalContent.html',
controller: 'ModalInstanceCtrl',
size: size,
resolve: {
items: function () {
return $scope.items;
}
}
});
modalInstance.result.then(function (selectedItem) {
$scope.selected = selectedItem;
}, function () {
$log.info('Modal dismissed at: ' + new Date());
});
};
$scope.toggleAnimation = function () {
$scope.animationsEnabled = !$scope.animationsEnabled;
};
});
// Please note that $modalInstance represents …Run Code Online (Sandbox Code Playgroud)