Skip to content

fix(ui-sref): Allow sref state options to take a scope object #1141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 24, 2014

Conversation

jhicken
Copy link
Contributor

@jhicken jhicken commented Jun 12, 2014

The tests pretty well outline the problem. Look at them if you want to see what is accomplished.

Basically when you try to use an object on a scope as your parameters for ui-sref. On a digest churn no updates occur. This fixes that problem.

$rootscope.scopeVar = {a:'1',b:'asd'}
ui-sref="something.something(scopeVar)"

@ProLoser
Copy link
Member

Is this just a convenient alternative to ui-sref="something.something({a:'1',b:'asd'})" which I think works too?

@jhicken
Copy link
Contributor Author

jhicken commented Sep 20, 2014

The idea is that... I keep a global object on $rootScope or in a service that contains my global url prams. Then you use that object from local or rootScope to populate all of your ui-srefs. So instead of doing this ui-sref="something.something({a:'1',b:'asd'})"... You would do ...

$rootscope.urlParams = {a:'1',b:'asd'}
ui-sref="something.something(urlParams)"

This also makes it so when you change one of the values inside your urlPramas your ui-srefs are updated to link to the correct place.

Without this when you change that urlParams object, ui-srefs simple ignore your changes until new DOM elements are loaded with new srefs.

@ProLoser
Copy link
Member

So I don't necessarily disagree that you should not be able to use the
syntax you mention, I don't run into your problem because I feel you are
creating two different "sources of truth" regarding the active params. For
me, the logic you are using to update your service or scope data should
probably just change the state directly and treat the params as readonly.
On Sep 20, 2014 2:46 PM, "Jeff Hicken" [email protected] wrote:

The idea is that... I keep a global object on $rootScope or in a service
that contains my global url prams. Then you use that object from local or
rootScope to populate all of your ui-srefs. So instead of doing this
ui-sref="something.something({a:'1',b:'asd'})"... You would do ...

$rootscope.urlParams = {a:'1',b:'asd'}
ui-sref="something.something(urlParams)"

This also makes it so when you change one of the values inside your
urlPramas your ui-srefs are updated to link to the correct place.

Without this when you change that urlParams object, ui-srefs simple ignore
your changes until new DOM elements are loaded with new srefs.


Reply to this email directly or view it on GitHub
#1141 (comment).

@jhicken
Copy link
Contributor Author

jhicken commented Sep 22, 2014

So thats great in most cases. In fact its really nice not having to worry about passing your urlParams in most cases. However this is a large application with some robust needs. My problem is I have 2 different state sets. Also I have a settings area that there is no place for url params in the URL (a third state set). Thats on purpose to avoid mixing state info. Also that settings page changes parts of the current url params objects. So I need to keep my url params for different states in a separate location.

@nateabele
Copy link
Contributor

This seems fine to me, but it looks like it needs to be rebased and cleaned up a bit. Also, there's already a describe() block for links, which would be the appropriate place for the new tests.

@jhicken
Copy link
Contributor Author

jhicken commented Sep 24, 2014

Rebased and moved the tests am I missing anything?

nateabele added a commit that referenced this pull request Sep 24, 2014
fix(ui-sref): Allow sref state options to take a scope object
@nateabele nateabele merged commit 07ee8a4 into angular-ui:master Sep 24, 2014
@nateabele
Copy link
Contributor

Nope, merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants