有条件地应用指令

编程入门 行业动态 更新时间:2024-10-25 13:30:10
本文介绍了有条件地应用指令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用 Material 2 添加 md-raised-button.我只想在特定条件成立时应用此指令.

I am using Material 2 to add md-raised-button. I want to apply this directive only if certain condition becomes true.

例如:

<button md-raised-button="true"></button>

另一个例子:我在 plunker 中创建了一个基本的动态反应形式.我正在为控件数组使用反应形式的 formArrayName 指令.我只想在特定条件为真时应用 formArrayName 指令,否则不要添加 formArrayName 指令.

Another example: I created a basic dynamic reactive form in plunker. I am using formArrayName directive of reactive form for array of controls. I want to apply formArrayName directive only if specific condition becomes true, otherwise don't add formArrayName directive.

这是一个 plunker 链接.

推荐答案

我不知道您是否可以根据条件应用指令,但 解决方法 将有 2 个按钮并根据条件显示它们.

I don't know if you can apply directives based on a condition, but a workaround would be having 2 buttons and display them based on a condition.

<button *ngIf="!condition"></button> <button *ngIf="condition" md-raised-button></button>

也许这会有所帮助.

更多推荐

有条件地应用指令

本文发布于:2023-05-27 23:11:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/306113.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:有条件   指令

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!