我想使用服务将一组员工 ID 发送到另一个组件。我有 2 个组件 - component1 和 component2。从 component1 我正在使用复选框选择员工。这是我的 component.ts 文件,我从中将员工 ID 数组发送到服务。
component1.ts 文件
checkbox_selected = []
ischecked: boolean;
constructor(private attendanceService: EmployeeService, private router: Router,
private fb: FormBuilder) { }
onChange(checkbox: any, isChecked: boolean) {
console.log("checkbox")
this.checkbox_selected.push(checkbox)
this.id = checkbox
this.ischecked = isChecked
console.log(this.checkbox_selected)
}
show(){
if(this.ischecked == true){
this.router.navigate(["./component2"])
this.attendanceService.my_employee_id(this.checkbox_selected);
}
服务.ts 文件
export class EmployeeService {
my_employee_id(id) {
console.log(id)
return this.emp_id;
}
}
在我的服务文件中,我正在获取员工 ID 数组。如何在另一个组件中获取这些员工 ID 数组?