0

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>
georgeawg
  • 48,608
  • 13
  • 72
  • 95
EnexoOnoma
  • 8,454
  • 18
  • 94
  • 179
  • This code is [tag:angularjs]. Please use the correct tags so people who can answer your question can also find it. – Igor Mar 19 '19 at 20:48
  • 2
    Are you intendedly using first version of angular, or would you like to use the most recent version? – GCSDC Mar 19 '19 at 20:48
  • @GCSDC yes, this is intentional. – EnexoOnoma Mar 19 '19 at 20:49
  • Possible duplicate of [if else statement in AngularJS templates](https://stackoverflow.com/questions/15810278/if-else-statement-in-angularjs-templates) – takendarkk Mar 19 '19 at 20:52

2 Answers2

2

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

anguiac7
  • 340
  • 4
  • 16
0

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>
Vishnu
  • 897
  • 6
  • 13