我正在使用 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>也许这会有所帮助.
更多推荐
有条件地应用指令
发布评论