当我尝试运行给定的示例代码时,出现此异常:
ckEditor.component.ts:类型“ CkEditorComponent”上不存在属性“ content”。导入CKeditor是否有任何错误。大多数的plunkr示例和示例程序都在旧的angular2上。使用最新的angular2我遇到了以上错误。
在此之前,我还在组件构造函数中获取this.content的异常,称其未定义
ckEditor.component.ts
import { Component } from '@angular/core';
@Component({
selector: 'ck-editor',
template: `
<ckeditor
[(ngModel)]="ckeditorContent"
[config]="{uiColor: '#99000'}"
(change)="onChange($event)"
(ready)="onReady($event)"
(focus)="onFocus($event)"
(blur)="onBlur($event)"
debounce="500">
</ckeditor>
`
})
export class CkEditorComponent{
constructor(){
this.ckeditorContent = `<p>My HTML</p>`;
}
}
app.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { CKEditorModule } from 'ng2-ckeditor';
import { CkEditorComponent } from './ckEditor.component';
@NgModule({
imports: [
BrowserModule,
FormsModule,CKEditorModule
],
declarations: [
CkEditorComponent
],
bootstrap: [CkEditorComponent]
})
export class AppModule { }
主要
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app.module';
platformBrowserDynamic().bootstrapModule(AppModule);
system.config.js
(function (global) {
System.config({
paths: {
// paths serve as alias
'npm:': 'node_modules/'
},
// map tells the System loader where to look for things
map: {
// our app is within the app folder
app: 'app',
// angular bundles
'@angular/core': 'npm:@angular/core/bundles/core.umd.js',
'@angular/common': 'npm:@angular/common/bundles/common.umd.js',
'@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
'@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
'@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
'@angular/http': 'npm:@angular/http/bundles/http.umd.js',
'@angular/router': 'npm:@angular/router/bundles/router.umd.js',
'@angular/router/upgrade': 'npm:@angular/router/bundles/router-upgrade.umd.js',
'@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
'@angular/upgrade': 'npm:@angular/upgrade/bundles/upgrade.umd.js',
'@angular/upgrade/static': 'npm:@angular/upgrade/bundles/upgrade-static.umd.js',
// other libraries
'rxjs': 'npm:rxjs',
'angular-in-memory-web-api': 'npm:angular-in-memory-web-api/bundles/in-memory-web-api.umd.js',
'ng2-ckeditor': 'npm:ng2-ckeditor',
},
// packages tells the System loader how to load when no filename and/or no extension
packages: {
app: {
main: './main.js',
defaultExtension: 'js'
},
'ng2-ckeditor': {
defaultExtension: 'js'
},
rxjs: {
defaultExtension: 'js'
}
}
map: {
"ng2-ckeditor": "node_modules/ng2-ckeditor/lib/ckeditor.component.js"
}
});
})(this);
而不是this.content
您应该使用this.ckeditorContent
变量。因为您将ckeditorContent
变量绑定到ckeditor组件。
<ckeditor
[(ngModel)]="ckeditorContent"
...
ckeditorContent
向您的组件添加变量
export class CkEditorComponent{
ckeditorContent = `<p>My HTML</p>`;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句