在 Angular 中整合
請先閱讀安裝與基本使用。以下範例透過 Angular 將 Univer Boards 掛載到具有明確高度的容器中。
整合步驟
- 在
ngAfterViewInit中初始化 Univer - 在
ngOnDestroy中銷毀 Univer
範例程式碼
TypeScript
import type { AfterViewInit, ElementRef, OnDestroy } from '@angular/core'import { Component, ViewChild } from '@angular/core'import { UniverBoardsPlugin } from '@univerjs-pro/boards'import { UniverBoardsUIPlugin } from '@univerjs-pro/boards-ui'import BoardsUIzhTW from '@univerjs-pro/boards-ui/locale/zh-TW'import { UniverInkUIPlugin } from '@univerjs-pro/ink-ui'import InkUIzhTW from '@univerjs-pro/ink-ui/locale/zh-TW'import { UniverLicensePlugin } from '@univerjs-pro/license'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 { UniverDrawingUIPlugin } from '@univerjs/drawing-ui'import DrawingUIzhTW from '@univerjs/drawing-ui/locale/zh-TW'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/drawing-ui/lib/index.css'import '@univerjs-pro/ink-ui/lib/index.css'import '@univerjs-pro/boards-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, DrawingUIzhTW, InkUIzhTW, BoardsUIzhTW, ), }, }) 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(UniverDrawingUIPlugin) univer.registerPlugin(UniverInkUIPlugin) univer.registerPlugin(UniverBoardsPlugin) univer.registerPlugin(UniverBoardsUIPlugin) univer.createUnit(UniverInstanceType.UNIVER_BOARD, {}) this.univer = univer } ngOnDestroy() { this.univer?.dispose() }}你覺得這篇文檔如何?