我如何重新加载/角度重新启动服务?
答
您可以使用工厂而不是简单的服务,并在其上创建一个reset
方法,将其设置为其“初始状态”。
例如,您可以工厂看起来是这样的:
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
};
}
}
'window.location.reload()'会重新加载应用程序...你不能“重启”的服务而不这样做。 .. –
重新启动后,你到底意味着什么?因为它是单身人士,所以只发生一次。 – SaiUnique