我无法使用angular 4设置 onhashchange 属性,我尝试在角度4的以下生命周期中设置onhashchange,但它无效。
ngAfterContentInit
ngAfterContentInit() {
//disabling browser back button
window.location.hash = "lienholder-details";
window.location.hash = "Again-lienholder-details";//again because google chrome don't insert first hash into history
window.onhashchange = function () { window.location.hash = "lienholder-details"; }
}
ngOnInit
ngOnInit(){
//disabling browser back button
window.location.hash = "lienholder-details";
window.location.hash = "Again-lienholder-details";//again because google chrome don't insert first hash into history
window.onhashchange = function () { window.location.hash = "lienholder-details"; }
}
如何在angular 4中设置onhashchange属性
答案 0 :(得分:1)
//View curr = parent.getChildAt((int) id);
View curr = parent.getChildAt(position);
//I'm getting an error here.
TextView c = (TextView) curr.findViewById(R.id.gorevNo);
或者如果您使用的是路由器
@HostListener('window:hashchange', ['$event'])
hashChangeHandler(e) {
window.location.hash = "lienholder-details";
}
答案 1 :(得分:0)
我使用了ngAfterViewChecked事件,我可以设置onhashchange属性