Allow empty states (aka: optional ui-sref)
I have noticed that the ui-sref directive is not optional, meaning I have to specify a state. I think this is too much of a constraint, because depending on the bound object on the a tag, one would want to bind to ng-href OR to ui-sref.
Is this somehow possible?
You can use ng-href already if the URL used matches your state's URL.
I mean, I have an 'a' tag that, depending on the bound object, has to use a link in 'ng-href' or a state in 'ui-sref'. If an instance has a related link, and not a state, 'ui-sref=""' throws an error.
Using ng-href and the $state service makes the trick! ;)
Closing.
+1 for empty state... or for some special value of 'disabled' link... Sure it can be written with ng-href, but with ui-sref it would be so much nice and cleaner...
+1
For example, how to ignore ui-sref in case you have some template for menu item, and not all items need ui-sref?
I think with empty state shouldn't be wrong?
@frapontillo please share your solution :)
I'm thinking @frapontillo probably did something roughly like this:
<a ng-href='$state.href(state.name)'></a>
Yep, I used the ngHref directive with a call to a custom function that returned an empty string (or the hash, I don't recall) or the $state.href call.
Thx.. i did the same.. I was thinking there is some other solution...
Hi, I have the same issue.
The problem with a custom solution is that I have to copy the whole uiSref directive (to keep uiSrefActive etc working) just to handle that case, it's not really maintainable.
What about a ui-sref-optional additional attribute to make it explicit that empty state references are ok?
+1
+1
+1
+1. I totally quote @guillaume86.
+1
+1
+1 That would be great !
+1
+1
+1
+1