Site navigation using ui-sref, how to remove ui-sref attribute when not available

自古美人都是妖i 提交于 2019-12-10 12:33:50

问题


I've setup navigation as follows, using ng-repeat, which works very well

<a ui-sref="{{link.Route}}" ng-click="clickLink(link)">
    <span class="title"> {{link.Text}} </span><span class="selected"></span>
</a>

However, my navigation items frequently have sublinks, which means the parent link isn't really a navigation link, it's just used to expand and view the sublinks. But sometime it is a link, and has no sublinks to display.

The problem is for those particular cases, when there is no state available, I need to remove the ui-sref all together, because there shouldn't be a link at all. Having it there is throwing 'Error: Invalid state ref '''

How do I remove the ui-sref when a state isn't available?


回答1:


You could use {{}} with expression

Markup

ui-sref="{{expression ? '.childState' : '.'}}"

. will create own state route, so while click on it, it will redirect no where.

Hope this could help you, Thanks.




回答2:


Conditionally create the ui-sref attribute

<a ng-attr-ui-sref="{{ link.Route ? link.Route : false }}">
    ...
</a>


来源:https://stackoverflow.com/questions/28568460/site-navigation-using-ui-sref-how-to-remove-ui-sref-attribute-when-not-availabl

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