converter/app/InputcomponentmanagerService.ts

41 lines
958 B
TypeScript
Raw Normal View History

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: ""
});
}
}