1
我試圖檢測加載此組件時是否按下了後退按鈕。在ngOnInit()中,我想知道Back是否被點擊,所以我不清除我所有的過濾器。下面是代碼:在Angular2中按下檢測返回按鈕
export class ProductListComponent implements OnInit, OnDestroy {
constructor (private _productsService: ProductsService, params: RouteParams, private _categoriesService: CategoriesService, private _filtersService: FiltersService, private _router: Router, private _location: Location) {
this.category = params.get('name') ? params.get('name') : null;
}
subscription: any;
category: any;
loading: boolean = false;
page: number = 1;
count: number;
products: any;
pages: Array = [];
errorMessage: string;
ngOnInit() {
this.getProducts();
//if(back button wasnt used) {
// this._filtersService.clear();
//}
this.subscription = this._filtersService.filterUpdate.subscribe(
(filters) => {
this.page = 1;
var params = this.category ? {name: this.category} : {};
this._router.navigate([this.currentRoute, params]);
this.getProducts();
}
);
}
是關於keydown事件而非選項? – Jinjubei
我需要檢測它是否回撥 – Karl