[英]Change Boolean values to button in angular 2 client side
I am trying to get data from api and show into the table. 我正在尝试从api获取数据并显示到表中。 One of the columns contains status attribute which return true or false value but I want to show Active or Block buttons instead of this status, ie.
其中一列包含status属性,该属性返回true或false值,但是我想显示Active或Block按钮而不是此状态。 if status is true then show delete button and if status==false show active button.
如果status为true,则显示删除按钮,如果status == false,则显示活动按钮。 How can I able to achieve this in angular 2.
如何在角度2中实现这一目标。
You could probably do something like this: 您可能会执行以下操作:
considering status:boolean=true;
考虑
status:boolean=true;
in your template you can use *ngIf as: 在模板中,您可以使用* ngIf作为:
<div>
<button *ngIf="status==true">Delete</button>
<button *ngIf="status==false">Active</button>
</div>
or you could also use ngSwitch
too. 或者您也可以使用
ngSwitch
。
Hope this helps. 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.