我正在尝试在组件之间共享信息。
是否有另一种方法可以与另一个组件共享信息?
我的组件 SportComponent
export class SportsComponent implements OnInit {
_sportId: any;
sportSummary: any[] = [];
sportGroup: any[] = [];
@Output() public SportGroupId: EventEmitter<string> = new EventEmitter<string>();
constructor(private _service: SportsService, private _routeParams: RouteParams) {
this._sportId = this._routeParams.get("id");
this.SportGroupId.emit(this.sportGroup);
}
ngOnInit() {
// Payload to cal the API
var model: SportsPayload = {
SportId: this._sportId
}
// Api loading
Observable.forkJoin(
this._service.getList(model)
)
.subscribe(
res => {
this.sportSummary = res[0];
this.sportGroup = res[0].SpID;
}
)
}
}
第二部分
export class SportsComponentList {
@Input() SportGroupId;
constructor() {
console.log(this.SportGroupId)
}
}