在编写一个包含Angular 2和多个计算服务的应用程序时,我遇到了以下问题:
- 什么时候在应用程序级别提供的Angular 服务中使用static?这是胡说八道吗?
- 静态方法如何反映性能?假设有几百个对象同时调用同一个静态方法.此方法是否多次实例化?
这是该类的快照,为我提供了多种计算方法,并在应用程序级别实例化:
@Injectable()
export class FairnessService {
constructor(){}
private static calculateProcentValue(value: number, from: number): number {
return (Math.abs(value) / Math.abs(from)) * 100;
}
public static calculateAllocationWorth(allocation: Allocation): number {
...
}
}
谢谢你的帮助.