关于 SAP Spartacus 注入服务 UserAccountService 和 facade 的问题
issue 里提到的 UserAccountService:
实现了 UserAccountFacade.
如果直接导入 UserAccountService:
import { UserAccountService } from ‘@spartacus/user/account/core’;
报错:
main.ts:14 Error: NullInjectorError: No provider for UserAccountService!
at NullInjector.get (core.js:1013) [angular]
at R3Injector.get (core.js:11173) [angular]
at R3Injector.get (core.js:11173) [angular]
at R3Injector.get (core.js:11173) [angular]
at injectInjectorOnly (core.js:899) [angular]
解决方案:
import { UserAccountFacade } from ‘@spartacus/user/account/root’
The actual services are lazily loaded, so that only when you use it, the additional js will be loaded. This requires however that you inject the facade instead, so that we can do the magic of loading the service lazily.
需要注入 facade,让 facade 执行延迟加载。
文章来自于网络,如果侵犯了您的权益,请联系站长删除!