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>
4
  • This code is angularjs. Please use the correct tags so people who can answer your question can also find it. Commented Mar 19, 2019 at 20:48
  • 2
    Are you intendedly using first version of angular, or would you like to use the most recent version? Commented Mar 19, 2019 at 20:48
  • @GCSDC yes, this is intentional. Commented Mar 19, 2019 at 20:49
  • Possible duplicate of if else statement in AngularJS templates Commented Mar 19, 2019 at 20:52

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

Comments

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>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.