【发布时间】:2017-12-06 09:41:10
【问题描述】:
我的目标是禁用浏览器窗口的后退按钮。因此,在我的组件中,我正在尝试侦听路径,因为我已经从 angular/common 导入了位置并尝试订阅它,但它似乎对我不起作用。这是我想禁用后退按钮的那个特定组件的代码 sn-p。
import { DataService } from './../../../shared/services/data.service';
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { Location } from "@angular/common";
@Component({
selector: 'app-confirmation',
templateUrl: './confirmation.component.html',
styleUrls: ['./confirmation.component.scss']
})
export class ConfirmationComponent implements OnInit {
userInput;
customWindow;
time;
message: string;
constructor(private location: Location, private dataService: DataService, private router: Router) {
this.dataService.currentMessage
.subscribe(message => (this.message = message));
console.log(this.message);
this.dataService.timeSource.subscribe(time => (this.time = time));
console.log(this.time);
}
ngOnInit(): void {
this.customWindow = window.open("", "_blank", "");
console.log('here');
console.log(this.location);
this.location.subscribe(x => console.log(x));
}
close () {
console.log(this.customWindow);
// this.customWindow.close();
console.log('666');
// this.router.navigate(['login']);
}
}
【问题讨论】:
标签: angular