Angular-cli 和 Ckeditor4 自定义构建

标签 angular typescript ckeditor4.x

我正在设置我自己的 CkEditor4 构建,我需要从我的 Angular-cli 应用程序访问它。我不知道如何访问我的 Angular 项目中的 ckeditor.js 文件。
我不想使用 CDN。

我查了CKEditor提供的文档:https://ckeditor.com/docs/ckeditor4/latest/guide/dev_angular.html

我知道我需要在我的项目中的某处写下这两行。

<script src="my-custom-build/ckeditor.js"></script>
<script src="your-app-bundle.js"></script>

我尝试了很多解决方案,但没有一个主题有效。
- 将 ckeditor.js 路径放在 angular.json 中的脚本中
- 将脚本标签放在 index.html 文件的标题中

包.Json
{
  "name": "web2print",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^7.2.15",
    "@angular/cdk": "^7.3.7",
    "@angular/common": "~7.2.0",
    "@angular/compiler": "~7.2.0",
    "@angular/core": "~7.2.0",
    "@angular/flex-layout": "^7.0.0-beta.24",
    "@angular/forms": "~7.2.0",
    "@angular/http": "^7.2.15",
    "@angular/material": "^7.3.7",
    "@angular/platform-browser": "~7.2.0",
    "@angular/platform-browser-dynamic": "~7.2.0",
    "@angular/router": "~7.2.0",
    "angular2-image-gallery": "^7.0.0",
    "ckeditor4-angular": "^0.1.2",
    "core-js": "^2.6.8",
    "cors": "^2.8.5",
    "express": "^4.17.0",
    "hammerjs": "^2.0.8",
    "ng2-ckeditor": "^1.2.2",
    "ng2-file-upload": "^1.3.0",
    "ngx-build-plus": "^7.8.3",
    "rxjs": "~6.5.2",
    "rxjs-compat": "^6.5.2",
    "screenfull": "^4.2.0",
    "tslib": "^1.9.0",
    "webpack": "^4.32.2",
    "webpack-cli": "^3.3.2",
    "zone.js": "~0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.13.0",
    "@angular/cli": "~7.3.9",
    "@angular/compiler-cli": "~7.2.0",
    "@angular/language-service": "~7.2.0",
    "@types/node": "~8.9.4",
    "@types/jasmine": "~2.8.8",
    "@types/jasminewd2": "~2.0.3",
    "codelyzer": "~4.5.0",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.11.0",
    "typescript": "~3.2.2"
  }
}

索引.html

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Web2print</title>
  <base href="/">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" type="image/x-icon" href="favicon.ico">
  <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
  <script src="ckeditor/ckeditor.js"></script>
</head>
<body>
  <app-root></app-root>
</body>
</html>


editor.component.ts

import {AfterViewChecked, Component} from '@angular/core';
import { CKEditorModule, CKEditorComponent } from 'ng2-ckeditor';



@Component( {
  selector: 'app-editor',
  templateUrl: './editor.component.html',
  styleUrls: [ './editor.component.css' ]
} )
export class EditorComponent {

}

错误信息:
GET http://localhost:4200/ckeditor/ckeditor.js net::ERR_ABORTED 404 (Not Found)

最佳答案

使用 build tool 配置 CKEditor 4 构建后,下载它,解压缩它,然后将它移动到“assets”文件夹中的一个目录中。我使用一个名为“供应商”的文件夹:

ckeditor file location

然后设置ckeditor组件的editorUrl参数:

<ckeditor [(ngModel)]="template"
  editorUrl="/assets/vendor/ckeditor/ckeditor.js"
  [config]="ckeditorConfig"
  (ready)="onEditorReady()">
</ckeditor>

关于Angular-cli 和 Ckeditor4 自定义构建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56342547/

相关文章:

ios - 位置 : fixed is not working in iOS when loading Angular site inside iframe in Ionic 3

angular - 在 Angular 的一项服务中使用 "ElementRef"时出错

javascript - 在 Typescript 中,扩展 Array 结果为 Array 类型,如何让它返回 List 类型?

typescript - Angular 2 RC4 RxJS 崩溃

c# - CKEditor 在 asp :textbox 上有空值

javascript - 将参数值组合到 Jquery 中的变量名

typescript - 如何从 Angular 2的服务中获取数据?

highcharts - angular2-highcharts Highcharts 导出模块

angular - 将 json 对象数据显示到下拉列表 Angular 2?

javascript - 特定部分的 ckeditor