简体   繁体   English

如果在 Angular 中满足条件,则创建一个 href

[英]Make an href if condition is met in Angular

I have different text that will be displayed in my template based on what gets returned from a service.根据从服务返回的内容,我的模板中将显示不同的文本。 Let's say: Initializing, Running, Done.让我们说:初始化,运行,完成。 In Angular, how do I make the text a link if the word matches Done?在 Angular 中,如果单词匹配完成,我如何使文本成为链接?

$scope.status = // Initializing, Running, or Done based on service

In the template, I want to show在模板中,我想显示

{{ status }} {{ 地位 }}

but when the status is Done, I want a hyperlink to go the actual result.但是当状态为完成时,我想要一个超链接来显示实际结果。 Do I need to use an ng-if, or is there a better way?我需要使用 ng-if 还是有更好的方法?

You can use ng-show and ng-hide to logically render what you want to show on your view.您可以使用ng-showng-hide逻辑地呈现您想要在视图中显示的内容。

In your case, you want to ng-show the link when status == 'Done' and ng-hide any other status when status == 'Done'在你的情况,你要ng-show的链接时, status == 'Done'ng-hide任何其他状态时, status == 'Done'

Here is a simple fiddle to illustrate https://jsfiddle.net/48fsbqvb/这是一个简单的小提琴来说明https://jsfiddle.net/48fsbqvb/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM