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

查看:26
本文介绍了在不使用 $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天全站免登陆