- Architecting Angular Applications with Redux,RxJS,and NgRx
- Christoffer Noring
- 107字
- 2021-08-27 19:56:15
Service without dependencies
A service without dependencies is a service whose constructor is empty:
export Service {
constructor(){}
getData() {}
}
To use it, you simply type:
import { Service } from './service'
let service = new Service();
service.getData();
Any module that consumes this service will get their own copy of the code, with this kind of code. If you, however, want consumers to share a common instance, you change the service module definition slightly to this:
class Service {
constructor() {}
getData() {}
}
const service = new Service();
export default service;
Here, we export an instance of the service rather than the service declaration.
推薦閱讀
- 解析QUIC/HTTP3:未來互聯網的基石
- OpenLayers Cookbook
- 物聯網概論(第2版)
- 面向物聯網的嵌入式系統開發:基于CC2530和STM32微處理器
- NB-IoT物聯網技術解析與案例詳解
- Socket.IO Real-time Web Application Development
- Metasploit Penetration Testing Cookbook
- 網絡環境中基于用戶視角的信息質量評價研究
- TD-LTE無線網絡規劃與設計
- 物聯網與智能家居
- 深入理解OpenStack Neutron
- 計算機網絡技術
- Web用戶查詢日志挖掘與應用
- Guide to NoSQL with Azure Cosmos DB
- NB-IoT原理和優化