I want to create a component in angular 2 that will take some input parameters.I am little bit confused about what should I use class or interface for input and why??For the following component I have used interface
import { Component, Input, Output, EventEmitter } from "@angular/core";
@Component({
moduleId: module.id,
selector: 'combo-compo',
template: `
<select name="theme" class="form-control" [ngModel]="selectedObject" (ngModelChange)="onChangeObj($event)">
<option [ngValue]="theme" *ngFor="let theme of dataObject" >{{theme.value}}</option>
</select>
`
})
export class ComboComponent {
selectedObject: ComboInterface;
@Input() dataObject: Array<ComboInterface>;
@Output() onComboChange = new EventEmitter();
onChangeObj(newObj: ComboInterface) {
this.selectedObject = newObj;
this.onComboChange.emit(this.selectedObject);
}
}
interface ComboInterface {
key: string;
value: string;
}