Hi Roman,
$scope.$apply() is meant for executing an expression in angular from
outside angular. Your $scope.$on()-callback is clearly already inside
angular, so you should not add another $scope.$apply() inside it. I suggest
you remove that and take a step back to the original problem.
--
thanks, Lars
inside the $scope.$on() callback seems incorrect and should
On Sunday, April 13, 2014 7:47:19 PM UTC+2, Roman wrote:
>
> I'm using $stateChangeStart with ui-router as a means of setting which
> direction a ui-view transition should go. I have a state history array and
> if the toState is the last state visited then I slide the view right
> instead of left so it looks like you are going "back" to the view, nothing
> too crazy.
>
> The original problem I had was that the ng-class wouldn't set properly on
> the current view, only the incoming view, so the current view wouldn't
> slide right off the screen. I slowed down the transition and in the chrome
> console saw that in fact the class was not being set to slide-right.
>
> It started to work perfectly when I added $scope.$apply(). When I make a
> transition using ui-sref I don't see any errors in the console. But when I
> used back/forward I get the $digest already in progress error.
>
> What's the difference between how the back/fwd buttons and ui-sref trigger
> a state change that would cause the error? Appreciate any insight!
>
>
> The controller:
>
> .controller('PublicController', function ($rootScope, $scope, $location,
> $anchorScroll) {
>
> $scope.$on('$stateChangeStart', function(e, toState, toParams, fromState,
> fromParams, error) {
>
> var hist = $scope.$parent.model.stateHistory;
>
> if (hist.length && hist[0].name === toState.name) {
>
> $scope.$parent.model.slideDirection = 'right';
> $scope.$apply();
> hist.shift();
>
> }
> else {
>
> $scope.$parent.model.slideDirection = 'left';
> $scope.$apply();
> hist.unshift(fromState);
> }
>
> $location.hash('');
> $anchorScroll();
> });
> })
>
>
> The view:
>
> <div class="main-public-view" ui-view="main.public"
> ng-class="{
> 'slide-left' : model.slideDirection === 'left',
> 'slide-right' : model.slideDirection === 'right'
> }"></div>
>
>
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.