在 Angular 中整合

請先閱讀安裝和基本使用。下面的範例在 Angular 元件中掛載 Univer Slides,併為容器設定明確的高度。

整合步驟

  1. 在 ngAfterViewInit 中初始化 Univer。
  2. 在 ngOnDestroy 中銷燬例項。

外掛設定

UniverUIPlugin

  • container
    string | HTMLElement
    編輯器掛載的 DOM 元素或元素 ID。

UniverLicensePlugin

  • license
    string
    用戶端授權檔的內容。

範例程式碼

TypeScript
import type { AfterViewInit, ElementRef, OnDestroy } from '@angular/core'import { Component, ViewChild } from '@angular/core'import { UniverLicensePlugin } from '@univerjs-pro/license'import { UniverSlidesPlugin } from '@univerjs-pro/slides'import { UniverSlidesUIPlugin } from '@univerjs-pro/slides-ui'import SlidesUIzhTW from '@univerjs-pro/slides-ui/locale/zh-TW'import SlideszhTW from '@univerjs-pro/slides/locale/zh-TW'import { LocaleType, mergeLocales, Univer, UniverInstanceType } from '@univerjs/core'import DesignzhTW from '@univerjs/design/locale/zh-TW'import { UniverDocsPlugin } from '@univerjs/docs'import { UniverDocsUIPlugin } from '@univerjs/docs-ui'import DocsUIzhTW from '@univerjs/docs-ui/locale/zh-TW'import { UniverDrawingPlugin } from '@univerjs/drawing'import { UniverRenderEnginePlugin } from '@univerjs/engine-render'import { UniverUIPlugin } from '@univerjs/ui'import UIzhTW from '@univerjs/ui/locale/zh-TW'import '@univerjs/design/lib/index.css'import '@univerjs/ui/lib/index.css'import '@univerjs/docs-ui/lib/index.css'import '@univerjs-pro/slides-ui/lib/index.css'@Component({  selector: 'app-univer',  standalone: true,  template: '<div #container style="height: 600px"></div>',})export class UniverComponent implements AfterViewInit, OnDestroy {  @ViewChild('container') containerRef!: ElementRef<HTMLDivElement>  private univer?: Univer  ngAfterViewInit() {    const container = this.containerRef.nativeElement    const univer = new Univer({      locale: LocaleType.ZH_TW,      locales: {        [LocaleType.ZH_TW]: mergeLocales(          DesignzhTW,          UIzhTW,          DocsUIzhTW,          SlideszhTW,          SlidesUIzhTW,        ),      },    })    univer.registerPlugin(UniverLicensePlugin, {      license: 'your license.txt',    })    univer.registerPlugin(UniverRenderEnginePlugin)    univer.registerPlugin(UniverUIPlugin, {      container,    })    univer.registerPlugin(UniverDocsPlugin)    univer.registerPlugin(UniverDocsUIPlugin)    univer.registerPlugin(UniverDrawingPlugin)    univer.registerPlugin(UniverSlidesPlugin)    univer.registerPlugin(UniverSlidesUIPlugin)    univer.createUnit(UniverInstanceType.UNIVER_SLIDE, {})    this.univer = univer  }  ngOnDestroy() {    this.univer?.dispose()  }}

你覺得這篇文檔如何?

© 2026 DreamNum Co., Ltd.