Note that there are some explanatory texts on larger screens.

plurals
  1. POwhy angular-ui new state router transitions when only parameters changes?
    primarykey
    data
    text
    <p>I'm using the <em>new</em> angular-ui router, the one that has a state-machine included (<a href="https://github.com/angular-ui/ui-router" rel="nofollow">https://github.com/angular-ui/ui-router</a>). This great router allows a user to specify parameters as part of the URL. </p> <p>for example: </p> <pre><code>$stateProvider .state('contacts.detail', { url: "/contacts/:contactId", templateUrl: 'contacts.detail.html', controller: function ($stateParams) { // If we got here from a url of /contacts/42 expect($stateParams).toBe({contactId: 42}); }] }) </code></pre> <p>(see <a href="https://github.com/angular-ui/ui-router/wiki/URL-Routing" rel="nofollow">here</a>)</p> <p>this means, that when the user navigates to /contacts/42, the state is changed to 'contacts.details' and the 42 parameter is injected into the controller </p> <p>There is a problem though. If ONLY the url parameter changes, the transitionTo function is still being called (could happen if the url is changed manually, for example, or bound to a input box). this in turn leads to the view directive of that state, to be re-created, both a waste of time and a problem if we only wanted to update something in that state.</p> <p>it seems to be on purpose. from the code:</p> <pre><code> // Starting from the root of the path, keep all levels that haven't changed var keep, state, locals = root.locals, toLocals = []; for (keep = 0, state = toPath[keep]; state &amp;&amp; state === fromPath[keep] &amp;&amp; equalForKeys(toParams, fromParams, state.ownParams); keep++, state = toPath[keep]) { locals = toLocals[keep] = state.locals; } </code></pre> <p>equalForKeys is what compares the params, and return false if there's a difference.</p> <p>My question: do you know why the author would have written it this way? do you think its safe to change, so that there's no transition when only parameters would change?</p> <p>thanks very much for reading all the way till here, and for any idea</p> <p>Lior</p> <p>EDIT: Seems that this is by design. just found: <a href="https://github.com/angular-ui/ui-router/issues/46" rel="nofollow">https://github.com/angular-ui/ui-router/issues/46</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload