0

So what I am trying to do is for an icon (link), the user will have already logged on and there is a property identified that is true or false. Based on whether that property is true or false, when the user clicks that icon (link), it will take them to one of 2 pages. So looking at different directives within angular, thought I could use ng-switch, but that doesn't seem viable so I thought ng-attr-href could do it. Trying something like (this is pseudo code):

<a href="somepage.html" ng-attr-href="object.value: false | goto: "otherpage.html""><span></span></a>

So this is like an if/else where when user clicks icon and that value true, they go one place, but if false, they go elsewhere. My difficulty is structuring that and how/where the else goes.

Is there a better way to do this than I am thinking based on what I shared?

Thanks much.

Adding to, where could this be wrong?:

                    <a ng-href="{{ ppt.Globals.value == 'false' '#/claimEnter' : '#/clearSwipe' }}">
                        <img src="ppt/assets/toolIcons/submiticon.svg" >
                        <p>Submit a Claim for Reimbursement</p>
                    </a>

2 Answers 2

3

Can use a ternary within a {{}} expression in ng-href

<a ng-href="{{object.value ? 'somepage.html' : 'otherpage.html'}}"> 
Sign up to request clarification or add additional context in comments.

2 Comments

Is the "?" mean to be the property? so object.value == 'false' ? 'somepage.html' : ..... ?
Added some additional detail hoping to get further input.
0

Put a function inside your controller to provide the value, then call it inside the ng-href. This type of decision of which link to go is the controller's responsibility.

ng-href="whereToGo(object.value)"

4 Comments

value is the property in this case. so is {{ object.property }} . That said, I understand the controller's responsibility. Just not sure I am understanding the syntax within the view as labeled. Meaning, so you saying that {{ function in controller ? whereToGo : another whereToGo }}. Do you see where I am lost?
I dont see why you are struggling with this... but the ternary operator could be used... but in this case I would go with the ng-click instead of ng-href
I am trying to understand what the '?' operator in there is supposed to do within the tenary. Guess it is trying to provide an 'if'. How would the ng-click go into this with an 'if'?
The ? operator works as an if... object.value ? "url1" : "url2"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.