有条件地应用指令 [英] Apply a directive conditionally

查看:62
本文介绍了有条件地应用指令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 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> 

也许会有所帮助.

这篇关于有条件地应用指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆