angular-route-segment icon indicating copy to clipboard operation
angular-route-segment copied to clipboard

Event routeSegmentChange called on routeParam change

Open alexunm opened this issue 10 years ago • 0 comments

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.

alexunm avatar Dec 02 '14 11:12 alexunm