Separate methods from an Angular component 6

0

Hello everyone, I have a component with 1266 lines, due to its large volume of methods, I need to separate these methods to facilitate future maintenance, only problem is that I have local variables, and these methods mostly consume these variables , how can I separate these methods without having to break all my code?

I tried to create a Heldp component, and my Main component would pass as parameters.

EX-component in the same "MyRdesp" directory

//ComponentPrincipal

export class ExpenseReportsFormComponent implements OnInit {

help: any; 

help = ComponentHelp

this.help.populateField(item,this) // this mandaria todo dados do meu component

}

//component que teria metodos
export class ComponentHelp{

//metodo
populateField(item:any,component:any){
// funlçoes  do meotdo 
component.form['controls']['itens']['controls'][i]['controls'].id.setValue(item.id);
          component.form['controls']['itens']['controls'][i]['controls'].currencyAlias.setValue(item.currencyAlias);
          component.form['controls']['itens']['controls'][i]['controls'].product.setValue(item.productId);
          component.form['controls']['itens']['controls'][i]['controls'].currency.setValue(item.currencyId);
          component.form['controls']['itens']['controls'][i]['controls'].productIcon.setValue(item.productIcon);
          component.form['controls']['itens']['controls'][i]['controls'].value.setValue(item.value);
}

}

But it gives me an error saying that method does not exist in ComponentHelp

Can anyone tell me why I can not do this? And what is the best way?

    
asked by anonymous 14.12.2018 / 11:17

0 answers