问题描述
我在nodewebkit应用程序中使用AngularJS 。
我有三种看法:
- Home.html中
- Conversation.html
- 的login.html
登录时,我正在打电话
$state.go('home.main');
哪个电话
$stateProvider.state('home.main', {
url: '/home',
views: {
"mainContent": {
templateUrl: 'views/home.html',
controller: 'loginController'
}
}
}
在主html中,我正在进行服务器调用(通过socket.io)以获取所有对话。 由于数据量巨大,因此需要花费一些时间来加载数据,并且在这个时间间隔内,即在用户从服务器获得响应之前,如果用户单击注销,它将使用户返回登录页面。
$scope.logout = function(){
//Logout Logic
$state.go('login');
}
即它调用
$stateProvider.state('login', {
url: '/login',
templateUrl: 'views/login.html',
controller: "loginController"
});
现在,当用户尝试登录时,服务器会响应呼叫以进行对话,从而允许用户将其转到/home/conv.html。
从服务器发送数据到客户端时,我不想禁用Logout按钮。
从/ home到/ login路由有什么办法,我们可以取消所有服务器调用吗?
1楼
quannguyen
0
2015-07-25 09:51:58
我从复制了代码:
$stateProvider.state("contacts", {
template: '<h1>{{title}}</h1>',
resolve: { title: 'My Contacts' },
controller: function($scope, title){
$scope.title = 'My Contacts';
},
onEnter: function(title){
if(title){ ... do something ... }
},
onExit: function(title){
if(title){ ... do something ... }
}
})
当您从home.main移到另一条路线时,将触发onExit事件。
因此,您应该在声明home.main路由的地方进行注册以处理该事件。
在这种情况下,您可以取消所有服务器调用。
在使用socket.io时,建议您使用函数socket.removeAllListeners();