本文介绍了我如何以角度重新加载/重新启动服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在不重新加载应用程序的情况下重新启动服务?
How can I restart a service without reloading an app?
我不想使用window.location.reload()
.
推荐答案
您可以使用工厂而不是简单的服务,并在其上创建一个 reset
方法,将其设置为初始状态".
You could use a factory instead of simple service and create a reset
method on it which would set it to its "initial state".
例如,您的工厂可能如下所示:
For example, your factory could look something like this:
function MyFactory() {
// generate the initial structure of the service
let Factory = _getDefaultFactory();
// expose the service properties and methods
return Factory;
/**
* Reset the factory back to its default state
*/
function reset() {
// generate the initial structure again
// and override the current structure of the service
Factory = _getDefaultFactory();
}
/**
* Generate a default service structure
*/
function _getDefaultFactory() {
return {
// include the reset method so you can call it later
// e.g. MyFactory.reset();
reset: reset
// include other factory properties and methods here
};
}
}
这篇关于我如何以角度重新加载/重新启动服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!