Using ng-attr-href from angular to direct user interaction

眉间皱痕 提交于 2019-12-12 06:18:19

问题


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>

回答1:


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

<a ng-href="{{object.value ? 'somepage.html' : 'otherpage.html'}}"> 



回答2:


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)"


来源:https://stackoverflow.com/questions/32595829/using-ng-attr-href-from-angular-to-direct-user-interaction

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!