barro32
barro32

Reputation: 2718

UI Router stateParams not updating in child routes

I had a route with a param working but then added some child routes and now it will not update.

Event Template

<a ui-sref="event.detail({id: event.id})" ng-repeat="event in events">
    Event {{event.id}}
</a>

UI Router

.state('event', {
    url: '/event',
    views: {
        'event': {
            template: ..., // shown above
            controller: 'Event'
        }
    }
})
.state('event.detail', {
    url: '/:id',
    views: {
        'event-detail': {
            template: ...,
            controller: 'EventDetail' // shows a single event
        }
    }
})
// tabs to switch between the different details
.state('event.detail.info', {
    url: '/info',
    views: {
        'event-info': {
            template: ...
        }
    }
})
.state('event.detail.map', {
    url: '/map',
    views: {
        'event-map': {
            template: ...
        }
    }
})
.state('event.detail.chat', {
    url: '/chat',
    views: {
        'event-chat': {
            template: ...
        }
    }
})

Controller

function EventDetail($scope, $stateParams) {
    $scope.getEventDetails = getEventDetails;

    $scope.getEventDetails($stateParams.id);

    function getEventDetails(id) {
        console.log(id); // returns correct first time, then nothing. Used to work every time!
        ...
    }
}

Run through of what's going wrong:

Upvotes: 1

Views: 499

Answers (1)

barro32
barro32

Reputation: 2718

The solution was to user cache: false in the event.detail states and it's child states.

Upvotes: 1

Related Questions