我有這樣的一個方法裏面角2無法讀取未定義的屬性「推送」。角2
exportClass AppComponent implements OnInit{
private averageList: number [] = number [];
(...)
getAverage(){
this.averageList = [];
(....)
(....)
var source = Observable.forkJoin(
this.http.get(data2.builds[0].url + this.finalURL),
this.http.get(data2.builds[1].url + this.finalURL)
);
var subscription = source.subscribe(
function (x) {
let numberOfFails = 0;
let count = 0;
for(var i = 0; i < x.length; i++){
let data = x[i].json();
contador++;
if (data.result === "FAILURE"){
numberOfFails++;
}
}
let average = numberOfFails/count;
console.log(numberOfFails + " " + count);
console.log(average);
this.averageList.push(average); //THIS LINE MAKES AN ERROR
},
function (err) {
console.log('Error: %s', err);
},
function() {
console.log('Completed');
});
}
}
當我嘗試將元素添加到陣列averageList出現下一個問題:無法讀取的未定義的屬性「推」。 在方法開始時,我使用this.averageList = []清理這個數組。 我該如何解決這個使用數組?謝謝
averageList是如何定義的?在提供的代碼中,我沒有看到它的定義。 –