I am working on Outlook Web Addin trying get it work using Angular 5, I have followed the official documentation provided by microsoft.
https://docs.microsoft.com/en-us/office/dev/add-ins/quickstarts/excel-quickstart-angular
yes the above link is for excel but the basic setup i can find its similar. I have initialized the Office in main.ts like
main.ts
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
import { environment } from './environments/environment';
if (environment.production) {
enableProdMode();
}
try{
Office.initialize = function () {
platformBrowserDynamic().bootstrapModule(AppModule);
};
}catch(err){
}
i am using routes in this addin which is declared and setup in app.module.ts the code is
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';
import { HttpModule } from '@angular/http';
import { LocationStrategy, HashLocationStrategy } from '@angular/common';
import { AppComponent } from './app.component';
import { ArchiveComponent } from './archive/archive.component';
import { SearchComponent } from './search/search.component';
@NgModule({
declarations: [
AppComponent,
ArchiveComponent,
SearchComponent
],
imports: [
BrowserModule,
HttpModule,
RouterModule.forRoot([
{
path:'archive',
component:ArchiveComponent
},
{
path:'search_archive',
component:SearchComponent
}
])
],
providers: [
{ provide: LocationStrategy, useClass: HashLocationStrategy },
],
bootstrap: [AppComponent]
})
export class AppModule { }
I have tested the routes /#archive in local it works and displays the html inside the ArchiveComponent template page. only when the bootstrap is not done in Office.initailize.
When i hosted the addin on my apache server and installed it in my outlook web it works for only first time. ArchiveComponent component code is below:
import { Component, OnInit } from '@angular/core';
declare const Office: any;
@Component({
selector: 'app-archive',
templateUrl: './archive.component.html',
styleUrls: ['./archive.component.css']
})
export class ArchiveComponent implements OnInit {
constructor(private zone: NgZone) { }
ngOnInit() {
console.log(Office.context.mailbox.item.itemId)
}
}
Console inside the oninit method prints in browser from Outlook web when opened first time, after that when i reopen the addin next time on same Outlook web it throws the error
Office.js has not fully loaded. Your app must call "Office.onReady()" as part of it's loading sequence (or set the "Office.initialize" function). If your app has this functionality, try reloading this page.
below is the image from console having 2 errors and 1st one is unknown but its from addin routes and 2nd one is Print 1st time
Same addin which is build by default angular version works great but facing problem when trying to migrate this to Angular 5.
I can guess that there is some thing which i am missing at the Office.initialize but not sure.
Reason to migrate is to use route inside the add-in so that for 2 different addins i don have create 2 projects.
