ui-router icon indicating copy to clipboard operation
ui-router copied to clipboard

Allow empty states (aka: optional ui-sref)

Open frapontillo opened this issue 13 years ago • 33 comments

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?

frapontillo avatar Sep 02 '13 09:09 frapontillo

You can use ng-href already if the URL used matches your state's URL.

nateabele avatar Sep 02 '13 18:09 nateabele

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.

frapontillo avatar Sep 02 '13 18:09 frapontillo

Using ng-href and the $state service makes the trick! ;) Closing.

frapontillo avatar Sep 03 '13 22:09 frapontillo

+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...

swayf avatar Mar 04 '14 18:03 swayf

+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 :)

vizo avatar Apr 01 '14 18:04 vizo

I'm thinking @frapontillo probably did something roughly like this:

<a ng-href='$state.href(state.name)'></a>

timkindberg avatar Apr 02 '14 02:04 timkindberg

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.

frapontillo avatar Apr 02 '14 06:04 frapontillo

Thx.. i did the same.. I was thinking there is some other solution...

vizo avatar Apr 09 '14 02:04 vizo

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?

guillaume86 avatar Aug 19 '14 07:08 guillaume86

+1

mweint avatar Aug 23 '14 01:08 mweint

+1

pedrodelgallego avatar Nov 25 '14 15:11 pedrodelgallego

+1

kiapanahi avatar Dec 01 '14 10:12 kiapanahi

+1. I totally quote @guillaume86.

dapids avatar Feb 11 '15 16:02 dapids

+1

lyadeski avatar Feb 18 '15 15:02 lyadeski

+1

mrb398 avatar Feb 18 '15 15:02 mrb398

+1 That would be great !

mvidailhet avatar Feb 23 '15 10:02 mvidailhet

+1

FMCorz avatar May 04 '15 08:05 FMCorz

+1

paulJordaan avatar May 08 '15 20:05 paulJordaan

+1

thearsenik avatar Sep 14 '15 13:09 thearsenik

+1

tabalinas avatar Nov 16 '15 16:11 tabalinas