Angular 6 Services: providedIn: 'root' vs CoreModule

后端 未结 7 911
猫巷女王i
猫巷女王i 2021-02-01 02:40

With Angular 6, below is the preferred way to create singleton services:

import { Injectable } from \'@angular/core\';

@Injectable({
  providedIn: \'root\',
})
         


        
7条回答
  •  梦谈多话
    2021-02-01 03:25

    I would still keep CoreModule for single use components and Http interceptors, with the providedIn property is now the recommended way to register singleton services, just for clarity I would put all my singleton services under core/services directory

提交回复
热议问题