简体   繁体   中英

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

ORIGINAL EXCEPTION: ReferenceError: CKEDITOR is not defined

Here is the code i have.

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

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.

在此输入图像描述

Anyone have any idea why this isnt working?

This means that your CKEDITOR JavaScript didn't load.

The file CKEditor.js refers to the Angular2 component which doesn't contain the editor itself. That file is part of the repo .

So you need to include ckeditor.js yourself.

I'm not sure about the condition on line 159 , which should detect missing CKEDITOR JavaScripts. Maybe show the entire error message on what line inside CKEditor.js it throws the error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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