html - Angular 9:创建使用其他标准指令的自定义指令
问题描述
我正在开发一个基于 Angular/Material 9 的小框架。我想创建自定义指令,将标准 Material 指令应用于其宿主元素。对于某些 UI 元素,我更喜欢使用指令而不是创建自定义包装组件(使用 ng-content)。例如,对于按钮,我想使用这样的“自定义按钮”指令:
<button type="button" custom-button>Hello world!</button>
该指令应将标准 Material 指令(以及其他一些属性)应用于宿主元素的按钮。呈现的 HTML 按钮应为:
<button type="button" custom-button mat-button mat-raised-button color="accent">Hello world!</button>
我知道如何设置属性/属性,但显然该按钮不像“真正的”垫子按钮(它没有由 Material 添加的自定义内部元素,也没有用于波纹效果)。我对 Angular 很陌生,所以我搜索了很多答案。但我只发现了非常复杂或过时的解决方案(AngularJS)。有什么帮助吗?
解决方案
推荐阅读
- python-3.x - 将大量大型 npy 文件合并为一个文件
- c++ - 容器和容器内容类型 C++ 的模板
- python - 如何计算表示每列中存在特定值的总和并计算每个 id 的总数?
- devise - 使用设计验证静态文件?
- python - 尽管看似独立,但对象依赖性仍然存在
- r - 使用正则表达式将 `.0` 添加到不带小数的数字末尾
- jsf - Netbeans 12 热部署到 Wildfly 16
- python - 似乎无法访问 html 中的元素
- php - 在上传恢复之前检查 json 文件的一致性
- url - 当我的 url 不以斜杠结尾时,为什么我的 gatsby 站点部署的路径前缀请求不存在的文件