【发布时间】:2021-07-02 14:51:06
【问题描述】:
我已经基于角度元素创建了自己的 web 组件。我都是按照说明书做的。
示例代码为:
const el = createCustomElement(AppComponent, { injector: this.injector });
customElements.define('my-widget', el);
我也有 ApplicationService:
@Injectable({ providedIn: 'root' })
export class ApplicationService {}
毕竟,当我运行漂亮的“我的小部件”元素时 - 1 个实例运行良好。但是如果我运行两次,看起来 ApplicationService 总是只运行一次(单个实例)。
例子:
<my-widget id="widget1"></my-widget>
<my-widget id="widget2"></my-widget>
我想实现每个人都有自己的实例。
我正在寻找解决方案,我注意到配置有额外的字段,如:strategyFactory in createCustomElement
{ injector: Injector; strategyFactory?: NgElementStrategyFactory; }
我不知道如何使用它。你有什么想法吗?
【问题讨论】:
标签: angular dependency-injection web-component angular-elements