此代碼是一個使用angularjs和typescript的ASP.net應用程序
在html文件中,有一個ng-repeat(用於填充表),它正在監視變量this.csvData (這是一個由private csvData = []
定義的實例變量)並且表格完美地生成。但是,當我在updateDataDict函數內部嘗試console.log時,控制檯返回[]。我不知道爲什麼....實例變量在Typescript中不保留值
public csvData = [];
private csvDataDict = {};
private getCSVdata() {
var locationType = document.getElementById('dropdownButton').innerText.toLowerCase();
console.log("Inside CSV data");
let dataArray = [];
this.$http.get(this.csvLocations[locationType]).then(function (res) {
var result = res.data.toString().split(/\r\n|\n/);
for (let i = 0; i < result.length; i++) {
let [sourceURL, redirectURL] = result[i].split(',');
dataArray.push({
sourceURL: sourceURL,
redirectURL: redirectURL
})
}
});
this.csvData = dataArray;
this.updateDataDict()
}
private updateDataDict() {
console.log(this.csvData); // this line is screwing up.....
}
this.updateDataDict()將在內部代碼之前執行。 –