用角度的方式,如何实例化在其构造函数中注入了服务的类

时间:2018-07-19 16:18:03

标签: angular

如何使用注入的服务来创建一个TypeScript类并实例化该类?假设您有一个Employee类,在其构造函数“ IEmployeeInfo”上具有一个参数以初始化对象,还具有注入的角度服务“ SomeService”。那么如何实例化该类呢?

export class Employee {
  constructor(employeeInfo: IEmployeeInfo, _someService: SomeService) {}
   //using the method from injected service
    this._someService.doSomething(employeeInfo);

   //methods
    soSomeStuff(){...}
    otherMethods(){..}
}



@Component({..})
export class employeeTransaction {
     // how to instantiate a new Employee object?
     const emp1 = new Employee(employeeArgs, service???);
     emp1.doSomeStuff();
     emp1.otherMethods();
}

0 个答案:

没有答案