Angular 6 Services: providedIn: 'root' vs CoreModule

后端 未结 7 910
猫巷女王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:18

    And what about interceptors and guards? This things can be global I guess. I agree with your consideration about CoreModule doesn't have declarations and only pure services, but I think Guards and Interceptors should be considerate too.

提交回复
热议问题