converter/app/inputcomponentmanager.service.ts

42 lines
No EOL
959 B
TypeScript

import {Injectable} from "@angular/core";
@Injectable()
export class InputComponentManagerService {
private components:any[] = [];
public constructor() {
}
public register(component:any):void {
this.components.push(component);
}
public getAllComponents():any[] {
return this.components;
}
public getNext(component:any):any {
let index:number = component.index;
if (index == this.components.length - 1) {
this.addComponent();
}
return this.components[index + 1];
}
public getFirst():any {
if (this.components.length == 0) {
this.addComponent();
}
return this.components[0];
}
private addComponent():void {
this.register({
content: "",
selectedConverter: undefined,
index: this.components.length,
error: false,
message: ""
});
}
}