简体   繁体   English

更改来自库的组件选择器

[英]Change Selector of Component coming from Library

Context语境

I am working on a user interface library - which in itself is consuming another Angular Library which provides own components (for the sake of the example let's assume it's the Angular Material Library. Some of the components provided are such a good fit, that I'd like to simply "hand them through" to the consumers of my library.我正在开发一个用户界面库 - 它本身正在使用另一个提供自己组件的 Angular 库(为了这个例子,我们假设它是 Angular Material Library。提供的一些组件非常适合,我我想简单地将它们“交给”我图书馆的消费者。

Problem问题

However, for consistency, I'd like to have a comment prefix: Instead of, say mat-button , I'd like to use the selector foo-button .但是,为了一致性,我想有一个注释前缀:我想使用选择器foo-button而不是mat-button foo-button

Is there a way to achieve such behaviour?有没有办法实现这种行为? To "rename" the selector for a component?要“重命名”组件的选择器?

I'd like to achieve this without wrapping the consumed component into an another component, because this would force me to write (and maintain) my own methods that mimik the wrapped components' API and delegate to the wrapped component.我想在不将使用的组件包装到另一个组件中的情况下实现这一点,因为这将迫使我编写(并维护)我自己的方法来模仿包装组件的 API 并委托给包装组件。

There is no other way of doing it apart from creating a wrapper component or to create directives to create these components dynamically and those directives having selector you want.除了创建包装器组件或创建指令以动态创建这些组件以及那些具有您想要的选择器的指令之外,没有其他方法可以做到这一点。 Because a component is responsive for defining its own selector, template etc. that servers as a Metadata for Angular.因为组件响应定义自己的选择器、模板等,这些选择器、模板等作为 Angular 的元数据服务。 It can't be overriden from any where else.它不能从其他任何地方被覆盖。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM