In Angular 1 my config looks like this:
$routeProvider
.when(\"/news\", {
templateUrl: \"newsView.html\",
controller: \"newsController\",
resol
@AndréWerlang's answer was good, but if you want the resolved data on the page to change when the route parameter changes, you need to:
Resolver:
@Injectable()
export class MessageResolver implements Resolve {
constructor(private messageService: MessageService, private router: Router) {}
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable {
const id = +route.params['id'];
return this.messageService.getById(id);
}
}
Your component:
ngOnInit() {
this.route.data.subscribe((data: { message: Message }) => {
this.message = data.message;
});
}