我正在尝试在组件之间共享信息。
是否有另一种方法与另一个组件共享信息?
我的组件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)
}
}