天天看点

SAP Spartacus directive学习笔记

directive: 目的是给DOM元素添加自定义行为,可以和Component class一样,实现life cycle hooks:

SAP Spartacus directive学习笔记

css selector:

在template中唯一标识一个Directive,并且触发Directive实例的初始化。

SAP Spartacus directive学习笔记
看一个错误:
SAP Spartacus directive学习笔记
SAP Spartacus directive学习笔记
答案:

you cant use input/output outside component / directive tag

正确做法?

SAP Spartacus directive学习笔记
SAP Spartacus directive学习笔记

in notification-message.component.html, it’s directly used in div tag

when I ctrl + click on line 3 above, it goes to line 12 in focus.directive.ts.

SAP Spartacus directive学习笔记

so it seems the name of selector and input are kept the same ON PURPOSE?

I think for small directives (single responsibility and single input) its simplified usage

————————————————

版权声明:本文为CSDN博主「汪子熙」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。

原文链接:

https://blog.csdn.net/i042416/article/details/113334525

继续阅读