无法在角2打字稿

无法在角2打字稿

问题描述:

我加载数据的数组转换成上装载一个数组变量(范围)像无法在角2打字稿

ngOnInit(){ 
    this.error = ""; 
    this.countries=[]; 
    this._countryService.getCountriesByRegion() 
    .subscribe(
     data => this.countries = data, 
     error => this.error = "keyword " + this.region + " is invalid." 
    ); 

然后onscrolling我级联另一个数组服务调用后Concat的与阵列保持器阵列与以往类似阵列

 onScroll() { 
     this._countryService.getCountriesfortesting() 
     .subscribe(
     data => this.countries.concat(data), 
     error => this.error = "keyword " + this.region + " is invalid." 
    ); 

} 

但在进入的getCountriesfortesting()成功的功能,this.countries持有nothing.So我无法前一阵与最新的阵列合并。 希望你可以理解。谢谢在adv :)借口错误,如果有的话。

你可以试试这个:

onScroll() { 
    this._countryService.getCountriesfortesting() 
    .subscribe(
    data => { 
     this.countries = this.countries.concat(data); 
    }, 
    error => this.error = "keyword " + this.region + " is invalid." 
); 

concat方法不更新源阵列,并返回concatened阵列。

参见本页:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat