UI路由器stateParams不在子路由中更新

时间:2016-05-05 17:38:45

标签: angularjs ionic-framework angular-ui-router

我有一个带有param工作的路线,但随后添加了一些子路线,现在它不会更新。

活动模板

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

UI路由器

.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: ...
        }
    }
})

控制器

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!
        ...
    }
}

彻底解决出错:

  • 点击Event 1
  • 网址更改为event/1并获取正确的活动详情
  • 返回列表并点击Event 2
  • 网址更改为event/2,但会显示活动1的详细信息
  • 点击信息,地图或聊天标签,网址从event/2更改为event/1/infoevent/1/mapevent/1/chat

1 个答案:

答案 0 :(得分:1)

解决方案是针对cache: false州及其子州的用户event.detail