If you need access to a function from several places, consider putting it in a service as @tibbus mentioned.
utility.service.ts
@Injectable()
export class UtilityService{
TestingFunction(){}
}
Next, make sure the service is listed in the providers array of your main module:
app.module.ts
// https://angular.io/docs/ts/latest/guide/ngmodule.html#!#ngmodule-properties
@NgModule({
imports: [ BrowserModule],
declarations: [ AppComponent, BuyTestComponent ],
providers: [ UtilityService ],
bootstrap: [ AppComponent ]
})
export class AppModule { }
You can then inject that service in any component that needs access to the function
buy-test.component.ts
@Component(...)
export class BuyTestComponent {
//inject service into the component
constructor(private util:UtilityService){}
TestHere() {
//access service function
this.util.TestingFunction();
}
}