I have this code in an Angular2 Microsoft Office Add-in project that displays an Office Dialog using the Javascript API.
Office.context.ui.displayDialogAsync(url, {height: 34, width: 20, displayInIframe: true},function (asyncResult) {
if (asyncResult.status !== Office.AsyncResultStatus.Succeeded) {
// TODO: Handle error.
return;
}
// Get the dialog and register event handlers.
dialog = asyncResult.value;
dialog.addEventHandler(Office.EventType.DialogMessageReceived, function (asyncResult) {
if (asyncResult.type !== Office.EventType.DialogMessageReceived) {
return;
}
this.router.navigate(['/user'],1);
dialog.close();
});
});
And I get this error:
TypeError: this.router is undefined
Where the router is defined in the component constructor.
constructor( private route: ActivatedRoute,
private router: Router,
private location: Location) { }
So the question is, how can I use that router inside the DialogEvenentHandler callback function to navigate to that URL?