Code Monkey home page Code Monkey logo

ngx-onlyoffice's Introduction

ngx-onlyoffice

Available on npm License GitHub last commit Maintenance Dependabot Status

This ONLYOFFICE wrapper for Angular displays the ONLYOFFICE viewer or editor in your Angular application.

Note, that you have to host the server yourself.

Installation

Type npm i ngx-onlyoffice in your command prompt.

Usage

See below or refer to the example.

Include the module in your app.module.ts.

import { NgModule } from "@angular/core";
import { BrowserModule } from "@angular/platform-browser";
import { NgxOnlyOfficeModule } from "ngx-onlyoffice";  // <-- here
import { AppRoutingModule } from "./app-routing.module";
import { AppComponent } from "./app.component";

@NgModule({
  bootstrap: [AppComponent],
  declarations: [
    AppComponent,
    ...
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    NgxOnlyOfficeModule, // <-- and here
    ...
  ],
  providers: [],
})
export class AppModule { }

Use in your template:

<onlyoffice [config]="myConfig"></onlyoffice>

An example config:

public myConfig = {
    /*
        editorConfig is the original config for onlyoffice, see docs under https://api.onlyoffice.com/editors/config/document
    */
    editorConfig: { 
      document: {
        fileType: "docx",
        info: {
          author: "Me",
          created: "26.11.19",
        },
        key: "3277238458",
        permissions: {
          download: true,
          edit: true,
        },
        title: "TestTitle",
        url: "example.com",
      },
      documentType: "text",
      editorConfig: {
        embedded: {
          embedUrl: "example.com",
          saveUrl: "example.com",
          shareUrl: "example.com",
          toolbarDocked: "top",
        },
        lang: "en",
        mode: "edit",
      },
      events: {
        onBack: console.log,
        onDocumentStateChange: console.log,
        onError: console.log,
        onReady: console.log,
        onRequestEditRights: console.log,
        onSave: console.log,
      },
      height: "100%",
      type: "desktop",
      width: "100%",
    },
    script: "https://office.example-server/web-apps/apps/api/documents/api.js", // <-- This is the api script URL.
  };

Config Changes

When you change the config, the editor will reload automatically. For this to work, you need to replace the entire config object. Just changing one property won't trigger a reload. Example:

// wrong
this.config.editorConfig.document.title = "New Title";

// right
this.config = {
  editorConfig: {
    document: {
      title: "New title",
      ...
    },
    ...
  },
  ...
}

Note that here you have to specify the whole configuration object, just some properties won't work.

However, if you just want to change some properties, you can use Object.assign like so:

this.config = Object.assign({}, this.config, {
    editorConfig: {
        title: "New Title"
    }
})

License

MIT

ngx-onlyoffice's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar greenkeeper[bot] avatar hrueger avatar snyk-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

ngx-onlyoffice's Issues

Document History

Hi, is the document history implemented in this onlyoffice wrapper component? ty

ngx-onlyoffice

npm ERR! Refusing to install package with name "ngx-onlyoffice" under a package
npm ERR! also called "ngx-onlyoffice". Did you name your project the same
npm ERR! as the dependency you're installing? @hrueger can you help with this

onSave is deprecated

It seems that onlyoffice has deprecated the onSave event and recommends using the callbackUrl now. The issue I am having is that when trying to include callbackUrl within the editorConfig, typescript is throwing a type error because 'callbackUrl' is not a property that is expected in the editorConfig object. In the source code, editorConfig appears to be of type 'any' but for some reason is enforcing a type during runtime. Do you have any suggestions on what I could change so that 'callbackUrl' can be included in the editorConfig object?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.