简体   繁体   English

扩展Kendo Angular 2 UI组件并使用所有Kendo组件功能创建我们自己的组件包装器

[英]Extending Kendo Angular 2 UI component and creating our own component wrapper with all Kendo component capabilities

I want to create one Angular 2 component which can wrap kendo-component with some other component. 我想创建一个Angular 2组件,它可以用一些其他组件包装kendo-component。

Something like below my-Component.component.html 像my-Component.component.html下面的东西

 <div class="my-component-wrapper"><br />
      <label>{{label}}<br />
        <mytooltipComp></mytooltipComp><br />
      </label><br />
    <kendo-dropdownlist<br />
        [data]="data"<br />
        [defaultItem]="defaultItem"<br />
        [textField]="'text'"<br />
        [valueField]="'value'"<br />
        [valuePrimitive]="true"<br />
        (ngModelChange)="updateData($event)"<br />
        (selectionChange)="handleSelection($event)"><br />
    </kendo-dropdownlist><br />   
   <div *ngIf="_dropdownControl.valid == false || this.value==null"><br />
        <p *ngIf="errorMsgShow">{{errorMsg}}</p><br />
      </div><br />
    </div><br />      

My wrapper.ts file has below component directive. 我的wrapper.ts文件有下面的组件指令。

@Component({
   selector: 'my-Component',        
   templateUrl: './my-Component.component.html'
})        

Now to use kendo component property I need to re-define same in my wrapper.ts file eg @Input('data') data: any; 现在使用kendo组件属性我需要在我的wrapper.ts文件中重新定义它,例如@Input('data')data:any;

to use my warped component I need following code 使用我的扭曲组件我需要以下代码

<my-Component
               [data]="genders"
               [label]="'mylable'"
               [isValidate]=true
               [showError]=true>
</my-Component>

My question is 我的问题是

As [data] is already property of kendo I don't want to re-define in wrapper.ts . 由于[data]已经是kendo的属性,我不想在wrapper.ts中重新定义。

Also wrapping of existing kendo component not allowing me to set other kendo related property like filtering etc. for that I need to again define same in wrapper.ts component. 还包装现有的kendo组件,不允许我设置其他与kendo相关的属性,如过滤等,我需要再次在wrapper.ts组件中定义相同的属性。

Is there any way I can use full capability of kendo inside my wrapper? 有什么办法可以在我的包装器中使用完全的kendo功能吗?

Once you decide to embed a kendo component in a wrapper, you isolate the kendo component from your page template, so you have no other choice than transfering properties through your wrapper. 一旦决定在包装器中嵌入kendo组件,就可以将kendo组件与页面模板隔离开来,因此除了通过包装器传输属性之外别无选择。

If your data comes from outside the wrapper you will need to define an @Input() data in your wrapper. 如果您的数据来自包装器外部,则需要在包装器中定义@Input()数据。 But you could also query an API to fill your data, and this can be done inside the wrapper. 但您也可以查询API来填充数据,这可以在包装器内完成。

Also, check out CustomValueAccessor, it is something you will need to implement in your custom control if you want it to integrate with Angular Forms and manage ngModel. 另外,请查看CustomValueAccessor,如果您希望它与Angular Forms集成并管理ngModel,则需要在自定义控件中实现它。

You can also benefit from inheritance, by creating a base dropdown component (which will do the ControlValueAccessor implementation and manage the base logic), and extending it for every type of dropdown you need. 您还可以通过创建基本下拉组件(将执行ControlValueAccessor实现并管理基本逻辑)以及为您需要的每种类型的下拉列表扩展它来从继承中受益。

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

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