首页 文章

Angular 6树可摇动提供者和懒惰模块

提问于
浏览
1

在Angular v6中,我们有了这个新功能,我们可以通过Injectable装饰器定义提供者范围 .

@Injectable({
  providedIn: 'root'
})
export class CounterService {
  num = Math.random();
}

这是否也解决了延迟加载模块获取不同实例的问题? ( forRoot()

1 回答

  • 1

    只有当您在 root 中注入服务时才会这样做,因为Treeshakeable Injector解析逻辑在延迟加载的场景中不起作用 .

    你可以看到this

相关问题