Ich verwende Angular 4 mit Office.js. Das Projekt wird von Angular CLI erstellt.Name nicht gefunden 'Büro'
Der Code ist einfach:
// declare const Office: any;
// With the line above, the app runs perfect
Office.initialize = function() {
platformBrowserDynamic().bootstrapModule(AppModule);
};
ich den Fehler bekam
Cannot find name 'Office'.
ich schon npm install --save-dev @types/office-js
Meine tsconfig.json Datei tat
{
"compileOnSave": false,
"compilerOptions": {
"outDir": "./dist/out-tsc",
"baseUrl": "src",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2016",
"dom"
]
}
}
UPDATE 1:
@MahmoodSajjadi Vorschlag, nach npm install --save @microsoft/office-js
Nach und verwenden
import { Office } from '@microsoft/office-js';
diesen Fehler Got:
ERROR in /my-app/src/main.ts (3,24): File '/my-app/node_modules/@types/office-js/index.d.ts' is not a module.
ERROR in ./src/main.ts Module not found: Error: Can't resolve 'office-js' in '/my-app/src'
@ ./src/main.ts 3:0-35
@ multi webpack-dev-server/client? http://localhost:4200 ./src/main.ts
In package.json, es tatsächlich ist "@microsoft/office-js": "0.0.0"
, nicht sicher, das ist ein richtiges Paket.
UPDATE 2:
Basierend auf Michaels Antwort scheint NPM Version nicht bereit ist, habe ich zunächst mit CDN-Version bleiben. Danke für die Hilfe von allen!
Sie müssen Office deklarieren oder importieren (als Code-Kommentar) –
@MahmoodSajjadi Wie kann ich richtig importieren? Ich habe 'import {Office} von 'office-js' versucht;' funktioniert aber nicht. –
das Paket '@ type/office-js' ist nur Typ Paket und nicht eine tatsächliche' office.js', brauchen Sie 'Npm ich @ microsoft/office-js' –