简体   繁体   English

ng2-ckeditor不在angular2应用程序中工作? 为什么?

[英]ng2-ckeditor not working in angular2 app? Why?

I am trying to use the ng2-ckeditor component in my angular2 application, but for some reason i keep getting an error in console saying 我试图在我的angular2应用程序中使用ng2-ckeditor组件,但由于某种原因我在控制台说不断收到错误

ORIGINAL EXCEPTION: ReferenceError: CKEDITOR is not defined 原始例外:ReferenceError:未定义CKEDITOR

Here is the code i have. 这是我的代码。

system.config.json system.config.json

(function(global) {
    // map tells the System loader where to look for things
    var map = {
        'app':                        'app', // 'dist',
        '@angular':                   'node_modules/@angular',
        'rxjs':                       'node_modules/rxjs',
        'angular2-tree-component':    'node_modules/angular2-tree-component',
        'lodash':                     'node_modules/lodash',
        'ng2-ckeditor':               'node_modules/ng2-ckeditor'
    };
    // packages tells the System loader how to load when no filename and/or no extension
    var packages = {
        'app':                      { main: 'main.js',  defaultExtension: 'js' },
        'rxjs':                     { defaultExtension: 'js' },
        'angular2-tree-component' : { main: 'dist/angular2-tree-component.js', defaultExtension: 'js' },
        'lodash' :                  { main: 'lodash.js', defaultExtension: 'js' },
        'ng2-ckeditor' :            { main: 'lib/CKEditor.js', defaultExtension: 'js' }
    };
    var ngPackageNames = [
        'common',
        'compiler',
        'core',
        'forms',
        'http',
        'platform-browser',
        'platform-browser-dynamic',
        'router',
        'router-deprecated',
        'upgrade'
    ];
    // Individual files (~300 requests):
    function packIndex(pkgName) {
        packages['@angular/'+pkgName] = { main: 'index.js', defaultExtension: 'js' };
    }
    // Bundled (~40 requests):
    function packUmd(pkgName) {
        packages['@angular/'+pkgName] = { main: '/bundles/' + pkgName + '.umd.js', defaultExtension: 'js' };
    }
    // Most environments should use UMD; some (Karma) need the individual index files
    var setPackageConfig = System.packageWithIndex ? packIndex : packUmd;
    // Add package entries for angular packages
    ngPackageNames.forEach(setPackageConfig);
    var config = {
        map: map,
        packages: packages
    };
    System.config(config);
})(this);

content.component.ts content.component.ts

import { Component, Input } from '@angular/core';
import { Content } from './models/content';
import { CKEditor } from 'ng2-ckeditor';

@Component({
    selector: 'content',
    template: '<ckeditor [(ngModel)]="content.text" [config]="{ uiColor: '#99000' }" debounce="500"></ckeditor>',
    directives: [ CKEditor ]
})

export class ContentComponent {

    @Input()
    content: Content;

    active: number = 1;
    sizes: number[] = [ 12, 11, 10, 9, 8, 7, 6, 4, 5, 3, 2, 1 ];

    getAnchor() {
        return '';
    }
}   

Can also see here that in my Network tab, the CKEditor.js file is being loaded. 也可以在这里看到,在我的网络选项卡中,正在加载CKEditor.js文件。

在此输入图像描述

Anyone have any idea why this isnt working? 任何人都知道为什么这不起作用?

This means that your CKEDITOR JavaScript didn't load. 这意味着你的CKEDITOR JavaScript没有加载。

The file CKEditor.js refers to the Angular2 component which doesn't contain the editor itself. 文件CKEditor.js引用的Angular2组件不包含编辑器本身。 That file is part of the repo . 该文件是回购的一部分

So you need to include ckeditor.js yourself. 所以你需要自己包含ckeditor.js

I'm not sure about the condition on line 159 , which should detect missing CKEDITOR JavaScripts. 我不确定159行的条件,它应该检测丢失的CKEDITOR JavaScripts。 Maybe show the entire error message on what line inside CKEditor.js it throws the error. 也许在CKEditor.js哪一行显示整个错误消息它会引发错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM