3

It's the strangest thing, I found the code that does exactly what I want: using ui-router to change the displayed URL without reloading the page. This is it:

$state.transitionTo($state.current, args, { location: true, inherit: false, notify: false});

The problem is, it only works the first time. After that line is called a second time, angular enters the apply/digest loop & my page breaks. The error shown in the console is:

TypeError: Cannot read property '$$nextSibling' of null
    at Scope.$digest (angular.js:12569)
    at Scope.$apply (angular.js:12805)
    at HTMLDivElement.<anonymous> (angular.js:19138)
    at HTMLDivElement.jQuery.event.dispatch (jquery.js:4641)
    at HTMLDivElement.elemData.handle (jquery.js:4309)
Liam Hession
  • 333
  • 2
  • 7
  • 1
    I should probably add that that call to `$state.transitionTo` is happening in the `$scope.watch` handler for a certain object in my model – Liam Hession Feb 06 '15 at 22:15
  • The issue revolves around `notify: false`. Still looking into this issue myself, but using `notify: true` is a lousy albeit working solution. – Kelly Feb 18 '15 at 23:03
  • Actually, turns out _toggling_ `notify` between `true` and `false` causes the issue for me. If I stick to one or the other, the problem goes away. Do you have other `transitionTo` or `go` calls that are defaulting to `notify: true`? – Kelly Feb 19 '15 at 17:12

1 Answers1

1

The first argument for the transitionTo() function is supposed to be a String (a state name), but you are passing it an Object (the current state object).

Instead of passing $state.current, you should pass $state.current.name:

$state.transitionTo($state.current.name, args, { location: true, inherit: false, notify: false});

Without looking at the UI-Router code, I can't say if this explains the error you are receiving.

Sunil D.
  • 17,983
  • 6
  • 53
  • 65
  • That wasn't it! It's interesting how transitionTo could recover from me passing the object though... – Liam Hession Feb 10 '15 at 19:17
  • @LiamHession I took a look at the source code and noticed that `transitionTo()` uses a helper function called [findState()](https://github.com/angular-ui/ui-router/blob/master/src/state.js#L115) that will accept either a state name or an object. So that mystery is solved. Sorry for the misleading advice. I also checked some of my own code where I reload a state. I've seen a lot of examples/work arounds for reloading states, but I've found this simple syntax works: `$state.go('stateName', {}, {reload: true})` Maybe that will help in your case. – Sunil D. Feb 11 '15 at 17:37