angular - 我想重用html
问题描述
假设我有 component 。
template:
<button class="my-own-button" (click)='handelClick($event)' [type]='this.type'>
<app-logo [src]="this.src">
</app-logo>
<ng-content>
</ng-content>
</button>
class MyButtonComponent {
@Input() src: string = "";
@Input() type: string = "button";
@Output() click = new EventEmitter<any>();
handelClick(event: any){
this.click.emit(event);
}
}
而且我仍然需要显式定义在 native 中已经存在的点击输出和类型输入道具。我只想添加一个 src 输入属性并在模板中提供一些额外的内容。
有什么办法可以解决吗?如果没有,您能否提出解决问题的最佳方法?
解决方案
尝试将按钮组件的选择器更改为属性选择器而不是元素选择器。这应该有助于在您的组件中保留本机按钮标签,同时实际上是一个 Angular 组件。Angular Material为其按钮使用属性选择器。
使用[my-button]
or[myButton]
代替my-button
作为组件选择器。
推荐阅读
- c++ - Unable to build surround360_render - CMake issue
- database - BCNF 分解 --- 我做错了吗?
- sql - 获取特定年份的产品
- c - 诸如“hello”之类的字符串实际上是 C 中单个字符的静态数组
- r - R - tidyverse/ggplot 条形图,带有自定义离散数据标签并按一个变量排序?
- android - How do I let the user move a circle into another circles by dragging it in Android?
- fortran - Breakpoint on MPI_ALLREDUCE in fortran function
- r - 附加到函数中的数据框 - 真的需要 globalenv
- jenkins - 詹金斯升级后缺少构建触发器部分
- html - 纯CSS中的响应式布局