Skip to content
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

Event routeSegmentChange called on routeParam change #81

Open
alexunm opened this issue Dec 2, 2014 · 0 comments
Open

Event routeSegmentChange called on routeParam change #81

alexunm opened this issue Dec 2, 2014 · 0 comments

Comments

@alexunm
Copy link

alexunm commented Dec 2, 2014

Hi,

I'm trying to get a route param whenever the route changes and i saw that the routeSegmentChange event it is called only when the route segment differs not when the route param has changed.

app.coffee

  $routeSegmentProvider
  .when('/primary', 'primary')
  .when('/primary/:id', 'primary.secondary')
  .segment('primary', {
      templateUrl: 'views/primary.html',
      controller: 'PrimaryCtrl'
    })
  .within()
  .segment('secondary', {
      templateUrl: 'views/primary/secondary.html',
      controller: 'PrimarySecondaryCtrl'
    })

PrimarySecondaryCtrl

angular.module('MyClientApp')
.controller 'PrimarySecondaryCtrl', ($scope, $routeSegment, $routeParams) ->
  $scope.id = $routeParams.id

  $scope.$on('routeSegmentChange', ()->
    $scope.id = $routeParams.id
  )

Also, because of the event being called only when the segment changes the filter is not working,
('id' | routeSegmentParam) == thing.id

To solve this problem i'me made this changes in the angular-route-segment.js:

line:222
Added:

var prevSegmentParams = {};

line:254
Added:

var paramsChanged = !angular.equals(prevSegmentParams, args.params);
if ((updates.length == 0) && paramsChanged) {
    broadcast(curSegmentPromise.success);
    prevSegmentParams = args.params;
}

Is this wrong, it's not suppose to work like this, is there a more elegant solution for my problem?

Thank you.

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

No branches or pull requests

1 participant