在SAP Spartacus产品明细页面用outlet显示自定义数据

首先建立一个新的Angular module和Component:html

这个新的module,由于要使用Outlet功能,因此须要从@Spartacus/storefront里导入OutletRefModule,以及导出咱们本身实现的MyOutletsComponent以便让外界消费。json

MyOutletsComponent的实现:app

在构造函数里注入currentProductService, 调用getProduct方法异步读取当前product属性,存储在属性product$里:异步

在这个Component的html里,显示product$的值:async

<ng-template cxOutletRef="ProductDetailsPageTemplate" cxOutletPos="before" let-model>
    <h1>Jerry</h1>
    <p>Product: {{ product$ | async | json }}</p>
</ng-template>

最后别忘了把Component的selector标签加到app Component的html里:函数

最后的效果:spa

要获取更多Jerry的原创文章,请关注公众号"汪子熙":
code