订阅该主题不起作用。为什么?

时间:2017-01-09 20:05:16

标签: angular

/*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,但它不起作用。

0 个答案:

没有答案