在组件Angular2之间传输数据对象

时间:2016-06-16 03:37:04

标签: angular angular2-template angular2-components

我正在尝试在组件之间共享信息。

是否有另一种方法与另一个组件共享信息?

我的组件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)
    }
}

0 个答案:

没有答案
相关问题