目前正在使用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);
}
]);发布于 2018-07-26 19:25:26
这是UI-路由器的一部分。您可以在这里找到文档:过渡钩
例如,当您从一种状态移动到另一种状态时,$transitions.onStart将注册一个转换钩子,该钩子将触发提供的函数。在您的示例中,它只会在退出所提供的状态时触发,在您的示例中,该状态为orders.view。
总结一下您提供的代码将做什么:当退出orders.view状态时,状态转换启动后将触发Socket.emit。
https://stackoverflow.com/questions/51546162
复制相似问题