/*import*/
@Component({
selector: 'supfoot-match-single',
templateUrl: './match-single.component.html',
styleUrls: ['./match-single.component.scss']
})
export class MatchSingleComponent implements OnInit, OnChanges {
private teamSearch = new Subject<any>();
@Input() match: Match;
names = {};
constructor(public teamService: TeamService) { }
ngOnInit() {
this.getTeamNames();
}
ngOnChanges() {
if (this.match) {
this.match.teams.forEach((team) => {
this.teamSearch.next(team.name);
})
}
}
getTeamNames() {
this.teamSearch.subscribe(key => console.log(key));
}
getTeam(key) {
return this.names[key];
}
}
我通过绑定属性和设置值 我调用方法getTeamsNames()来订阅主题teamSearch,但它不起作用。