angularjs - AngularJS - 什么是 $transitions?
问题描述
目前正在使用 AngularJS + NodeJS 应用程序,突然间我看到了这段代码:
$transitions.onStart({exiting: 'orders.view'}, function(trans) {
Socket.emit('orders:leave', {id_order: trans.params('from').id_order});
});
$transitions
帮我找出午餐吃什么。
谢谢。
答案编辑后:
对于那些最终登陆这里的人,您基本上可以在这些过渡中做任何您想做的事情;包括在退出 X 状态时做一些事情。
'use strict';
// Configuring the orders module
angular.module('orders').run(['Menus','MODULE_LIST', 'Authentication', '$transitions', 'Socket', '$templateCache',
function(Menus, MODULE_LIST, Authentication, $transitions, Socket, $templateCache) {
$transitions.onStart({exiting: 'orders.view'}, function(trans) {
alert('Alert function has stopped you from going further BEEP BOOP')
Socket.emit('orders:leave', {id_order: trans.params('from').id_order});
});
var stlViewPopoverHtml =
'<div>' +
'<img ng-src="{{url}}" height="{{height}}" width="{{width}}">' +
'</div>';
$templateCache.put('stl-preview-popover.html', stlViewPopoverHtml);
}
]);
解决方案
这是 UI-Router 的一部分。你可以在这里找到文档:Transition Hooks
例如$transitions.onStart
,当您从一种状态移动到另一种状态时,将注册一个触发提供的函数的转换钩子。在您的示例中,它只会在退出提供的状态时触发,在您的情况下,状态是orders.view
.
总结一下您提供的代码将做什么:退出orders.view
状态时,Socket.emit
一旦状态转换开始就会触发 。
推荐阅读
- java - 测试容器的初始化脚本无法正常工作
- rust - 如何在 tokio 中发送 json 作为响应并从 rust lang 包装库
- amazon-cloudwatch - 使用 Java cdk 设置 MetricFilter 维度
- graphql - Prisma v2:生成一个 .graphql 文件来编辑?
- rust - 如何使用 winit rust crate 中的 raw_window_handle() 方法?
- python - 在 Python for 循环中为变量动态分配名称
- sql - AWS Timestream:如何选择 OHLC 值?
- python - 为什么 pool.map 会删除数据操作?
- c - 在 C 中添加 2 个 void 指针数组
- docker - 无法在基于 apache/zeppelin:0.9.0 的 Docker 映像中安装软件包