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

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

问题描述

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

这是一个插件链接.

推荐答案

我不知道您是否可以根据条件应用指令,但是解决方法将具有 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天全站免登陆