在不使用$ rootScope的情况下使用angular ui路由器阻止stateChange [英] Prevent a stateChange with angular ui router without using $rootScope

查看:83
本文介绍了在不使用$ rootScope的情况下使用angular ui路由器阻止stateChange的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的用户可以保留一个状态,但是在我要显示模式对话框您要保存吗?"之前

My user can leave a state but before I want to show a modal dialog "Do you want to save?"

仅当用户数据变脏时才表示已更改.

ONLY if the user data is dirty that means changed.

我不想要的是将EditController中的isDirty属性粘贴到$ rootScope上,进入stateChangeStart事件,并在其中检查isDirty,然后显示/不显示保存对话框.

What I do NOT want is to stick a isDirty property in my EditController to the $rootScope go to the stateChangeStart event and check there for isDirty and then show/not the save dialog.

防止全局变量说明每本javascript初学者...

Prevent global variables says every javascript beginner book...

1.)那么,在不侵入$ rootscope的情况下防止状态改变的专业方法是什么?

1.) What is then the pro way to prevent a state change without hacking the $rootscope?.

2.)是否有用于ui-router的帮助程序库来增强ui-router在控制器内部提供功能挂钩的功能,以封装ui逻辑?

2.) Are there any helper libraries for ui-router which enhance the ui-router offering function hooks inside the controller to encapsulate the ui logic?

推荐答案

(1)根据您可以在适当的情况下将$ rootScope更改为$ scope.

You could change $rootScope to $scope wherever appropriate and works.

将自定义数据附加到状态对象下,您可以传递自定义数据.

Under Attach Custom Data to State Objects, you can pass on custom data.

(2)我不确定您要问的是什么,但是工厂/服务/提供者确实会有所帮助.

(2) I'm not sure what you're asking but factories/services/providers would really help.

这篇关于在不使用$ rootScope的情况下使用angular ui路由器阻止stateChange的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆