# ng2-umeditor

> simple uemditor for angular4.0

Latest version **1.0.4** (published 2017-08-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install ng2-umeditor
pnpm add ng2-umeditor
yarn add ng2-umeditor
bun add ng2-umeditor
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2017-08-05 |
| First published | 2017-07-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | hello1024 |
| Maintainers | www.cool1024.com |
| Keywords | uemditor, rich-editor, php |

## Links

- npm: https://www.npmjs.com/package/ng2-umeditor
- npm.io page: https://npm.io/package/ng2-umeditor

## Alternatives

- [@mdxeditor/editor](https://npm.io/package/@mdxeditor/editor.md) — 962.4K weekly downloads
- [mmdb-lib](https://npm.io/package/mmdb-lib.md) — 680.9K weekly downloads
- [playcanvas](https://npm.io/package/playcanvas.md) — 36.2K weekly downloads
- [@glw907/cairn-cms](https://npm.io/package/@glw907/cairn-cms.md) — 967 weekly downloads
- [markdown-to-confluence](https://npm.io/package/markdown-to-confluence.md) — 103 weekly downloads

## Recent versions

- 1.0.4 (latest) — 2017-08-05
- 1.0.3 — 2017-07-08
- 1.0.2 — 2017-07-07
- 1.0.1 — 2017-07-07
- 1.0.0 — 2017-07-07

## README

# ngx-umeditor
Angular4.x for Baidu UMeditor



## 说明

+ 支持图片上传（跨域问题测试通过），不支持百度地图（未解决报错问题）
+ 提供了原生UM对象，可自定义操作

## 使用

### 1、获取ng2-umeditor

```
npm install ng2-umeditor --save

```

将包内umeditor文件夹复制到项目的assets目录中

引入css样式（.angular-cli.json）

```json
...

"styles": [
        "assets/umeditor/themes/default/css/umeditor.css",
        "styles.css"
      ],
...

```


把 `Ng2UmeditorModule` 模块导入到你项目中。

```typescript
import { Ng2UmeditorModule } from 'ng2-umeditor';

@NgModule({
    imports: [..., Ng2UmeditorModule ],
    ...
})
export class AppModule { }
```

### 2、Example

```html

<!--test.component.html:-->

<app-ng2-umeditor
         [config]="config"
         [content]="content"
         (onLoad)="onLoad($event)"
         (onChange)="onChange($event)">
</app-ng2-umeditor>
```

```typescript

//test.component.ts:

import { Component, OnInit, Input, Output, EventEmitter, ViewChild } from '@angular/core';

@Component({
  selector: 'app-test',
  templateUrl: './test.component.html',
  styleUrls: ['./test.component.css']
})
export class TestComponent implements OnInit {


  constructor() { }

  ngOnInit() { 

    //模拟数据请求过程
    setTimeout(_=>{
        //如果编辑器初始化成功设置初始值
        if (this.um != undefined) this.um.setContent(this.content);
    },3000)

  }

  onLoad(um:any){
      //文本编辑器加载成功后，获取UM对象
      console.log(um);
      this.um=um
      this.um.setContent(this.content)
  }

  onChange(content: string){
      //文本内容改变时获取新的内容
      this.content=content;
  }

  content: string;

  //编辑器配置
  config: any = {
    toolbar: [
      'source | undo redo | bold italic underline strikethrough | superscript subscript | forecolor backcolor | removeformat |',
      'insertorderedlist insertunorderedlist | selectall cleardoc paragraph | fontfamily fontsize',
      '| justifyleft justifycenter justifyright justifyjustify |',
      'link unlink | emotion image ',
      '| horizontal print preview fullscreen'],
    imageUrl: 'http://www.example.com/upload',//图片上传链接
    imagePath: '/'//图片保存路径
  }

  //编辑器对象
  um:any

}

```


## 参考说明

### 主动获取编辑器内容

```typescript

//test.component.ts:

...

um:any

content:any

onLoad(um:any){
      //文本编辑器加载成功后，获取UM对象
      this.um=um;
      //获取文本内容
      this.um.getContent();
}

...

```

---
_Source: https://npm.io/package/ng2-umeditor · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
