我的目标是从Angular组件发送数据到服务中并使用服务方法对其进行处理。例如:
export class SomeComponent {
public data: Array<any> = MyData;
public constructor(private myService: MyService) {
this.myService.data = this.data;
}
}
和服务:
@Injectable()
export class TablePageService {
public data: Array<any>;
constructor() {
console.log(this.data);
// undefined
}
}
获取数据未定义。如何使其正常工作?