Angular2/TypeScript component for objects of certain type

I am trying to create an Angular component "EditComponent" that will transclude other Angular components who are all expected to implement a certain interface.

My "EditComponent" is purely a container for the hosted components and allows user to choose to edit/save/delete the object in the instance component.

If all the objects I am going to use in this EditComponent implement an "isValid()" method how can I bind my saveButtons' [disabled] property to this method?

For instance, if I knew the concrete object would be a HolidayEditComponent I would use the below in the EditComponent:

@ViewChild(HolidayEditComponent) editComponent: HolidayEditComponent;

and I could then have a method in my EditComponent return the valus of this objects' isValid() method:

childIsValid(){
    return this.editComponent.isValid();
}

then in the markup of the EditComponent I could bind to this:

<button [disabled]="!childIsValid()" *ngIf="isEditMode" class="btn btn-sm btn-outline-primary" (click)="save()">

How can I do this so editComponent is any object that implements IEditableObject?

链接地址: http://www.djcxy.com/p/40698.html

上一篇: 如何设置一个双向绑定到一个有效的引用,但空/新对象

下一篇: Angular2 / TypeScript组件用于特定类型的对象