简体   繁体   English

将Kendo UI包装到Angular 2组件中

[英]Wrap Kendo UI into a Angular 2 component

I am trying to get a regular Kendo UI widget (Editor) wrapper into an Angular 2 component. 我正在尝试将常规Kendo UI小部件(编辑器)包装放入Angular 2组件。 Is this possible. 这可能吗。 Has anyone done it? 有人做过吗?

I am aware of the Kendo UI 2 for Angular suite and I am using it already, but was wondering if the missing widgets can be still used with Angular 2. 我知道Kendo UI 2 for Angular套件,并且已经在使用它,但是想知道丢失的小部件是否仍可用于Angular 2。

Thanks 谢谢

So, here is how I did it: 因此,这是我的操作方式:

  • First I included jQuery in Index.html. 首先,我将jQuery包含在Index.html中。 I used the CDN link. 我使用了CDN链接。

  • Then I got the Kendo UI scripts I needed. 然后,我得到了所需的Kendo UI脚本。 I used http://www.telerik.com/download/custom-download to create a smaller file. 我使用http://www.telerik.com/download/custom-download创建了一个较小的文件。

  • Then I created a component to wrap the kendo widget: 然后,我创建了一个包装kendo小部件的组件:

 import { Component, Input, Output, EventEmitter, ElementRef, AfterViewInit } from '@angular/core'; declare var $: any; //inject jQuery @Component({ moduleId: module.id, selector: 'editor', template: ` <textarea>{{ text }}</textarea> `, }) export class EditorComponent { @Input() text: string; @Output() onTextChanged = new EventEmitter<string>(); constructor(private elem: ElementRef) { } ngAfterViewInit() { var ta = this.elem.nativeElement.children[0]; var self = this; $(ta).kendoEditor({ tools: [ "bold", "italic", "underline", "strikethrough", "justifyLeft", "justifyCenter", "justifyRight", "justifyFull", "insertUnorderedList", "insertOrderedList", "indent", "outdent", "createLink", "unlink", "insertImage" ], change: function () { self.onTextChanged.emit(this.value()); } }); } } 

  • Then to use it, I just declare it as : 然后使用它,我只声明为:

 <editor [text]="'Hello from the outside'" (onTextChanged)="editorTextChanged($event)" ></editor> 

  • and then I just handle the editorTextChanged event. 然后我只处理editorTextChanged事件。

I know this is not exactly the Angular way, but it works. 我知道这不完全是Angular的方法,但是它可以工作。 If anyone has a better way of doing this, please share it here. 如果有人有更好的方法,请在这里分享。

Thanks. 谢谢。

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

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