Install office type definition:
npm install --save @types/office-js
In tsconfig.app.json you add:
"types": [
"office-js"
]
In main.ts you bootstrap app as:
Office.initialize = function () {
platformBrowserDynamic().bootstrapModule(AppModule);
};
In index.html you add:
<script type="text/javascript" src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js"></script>
After that you should be able to write something like this in your angular service:
getExtension(): string {
if (Office.context.host === Office.HostType.Word) {
return '.docx';
} else if (Office.context.host === Office.HostType.Excel) {
return '.xlsx';
} else if (Office.context.host === Office.HostType.PowerPoint) {
return '.pptx';
} else {
return null;
}
}
Here you can find a sample of angular office-js project:
Angular office-js sample project
It is Angular 6 build with Angular CLI version 6.0.8
declare const Excel: any; declare const Office: any;
below the import statements in the javascript file. – Fluous Nov 23 '18 at 12:30