Block routing if form is dirty [ Angular 2 ]

巧了我就是萌 提交于 2019-12-13 16:03:12

问题


I am blocked with this,
In Angular 2, I need to block any user click event, even browser refresh if the form in the page is dirty

Could you help me with ideas?


回答1:


It seems you are looking for canDeactivate

It allows you to block routing away. You would need a shared service where you update the forms dirty state so that the guard can access it.




回答2:


The angular docs cover this exact question:
https://angular.io/guide/router#candeactivate-handling-unsaved-changes I'd leave that as a comment but I lack the reputation to do so.



来源:https://stackoverflow.com/questions/39091338/block-routing-if-form-is-dirty-angular-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!