1
我是新來的角2和試圖整合tinymce角2,但我無法在我的項目中使用tinymce。到目前爲止我所做的是我在我的項目中使用bower安裝tinyMCe。所有js文件都成功添加到我的項目中。然後我說在如下頁面佈局的所有引用:如何在angular 2中添加TinyMce?
<script src="~/lib/tinymce/tinymce.js"></script>
<script src="~/lib/tinymce/themes/modern/theme.js"></script>
<script src="~/lib/tinymce/plugins/link/plugin.js"></script>
<script src="~/lib/tinymce/plugins/paste/plugin.js"></script>
<script src="~/lib/tinymce/plugins/table/plugin.js"></script>
在此之後,我寫了組件在那裏我將使用tineMce如下:
import { Component, OnInit } from "@angular/core";
import { Routes, RouterModule } from "@angular/router";
import { NgForm } from "@angular/forms";
import Page = require("../../interfaces/iPage");
import PageService = require("../../services/page.service");
@Component({
//no need for selector as it will be loaded via routing
templateUrl: "/page/addEdit"
})
export class AddEditPageComponent implements OnInit {
model = this.newModel();
errorMessage: any;
tinymce: any;
constructor(private pageService: PageService.PageService) {
this.tinymce.init({
selector: "[tinymce]"
});
}
ngOnInit() {
}
newModel(): Page.IPage {
return {
pageId: 0,
pageName: null,
title: null,
content:null
};
}
submitForm(form: NgForm) {
debugger;
this.pageService.save(this.model).subscribe(model => {
this.model = this.newModel();
},
null);
}
}
然後我在下面的HTML代碼添加textarea的:
<textarea class="form-control" name="model.content" [tinymce]="tinymce" style="height: 300px" [(ngModel)]="model.content" placeholder="Description"></textarea>
我的頁面工作正常,當我不使用TinyMCE的,但是當我使用TinyMCE的,那麼這個錯誤出現吊屏幕上: 模板解析埃羅rs: 無法綁定到'tinymce',因爲它不是'textarea'的已知屬性。
如果我刪除textarea的,但不要由init刪除TinyMCE的那麼這個錯誤出現: 類型錯誤:無法讀取屬性未定義
「初始化」我不知道我做錯了。請幫助。
偉大的工作,埃文斯! –
謝謝@Evans。它像冠軍一樣奔跑。你讓我今天一整天都感覺很好。非常感謝。 – Umer
如何將內容設置爲小型mce編輯器? –