我有一个带有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/info
,event/1/map
和event/1/chat
答案 0 :(得分:1)
解决方案是针对cache: false
州及其子州的用户event.detail
。