EnexoOnoma
EnexoOnoma

Reputation: 8836

How to create a simple if then else in angularjs?

I am a beginnner in angularjs, and I want to make an if statement to the following code. Pseudocode:

if url.page exists then show this

 {{url.page | decodeURIComponent}}

else show 

{{url.path | decodeURIComponent}}

How can I achieve this?

This is my source code:

<a href="{{vm.company_website}}{{url.path}}"
   ng-if="url.path.indexOf('http') != 0"
   target="_blank"
   data-placement="bottom" data-toggle="tooltip" class="tip" 
   data-original-title="{{url.path}}" style="color:rgb(98, 98, 98);"
>
   {{url.page | decodeURIComponent}}
</a>

Upvotes: 0

Views: 53

Answers (2)

Vishnu
Vishnu

Reputation: 897

you can probably use the ng-href directive, a sample use can be as:-

<div ng-init="myVar = undefined">
 <h1>Tutorials</h1>
 <a ng-href="{{myVar !== undefined ? myVar : 'http://sample.site.com'}}">Test</a>
</div>

Upvotes: 0

anguiac7
anguiac7

Reputation: 340

{{url.page ? url.page : url.path | decodeURIComponent}} should do what you're wanting.

Upvotes: 2

Related Questions