Wie kann ich this.firms
in einem Daten forEach()
anrufen?Angular2 forEach kann Eigenschaft lesen
Ich weiß, wie dies in Angular1 zu tun, aber nicht mit meinem aktuellen Projekt in Angular 2.
Derzeit funktioniert es gut außerhalb des forEach, aber nicht innerhalb.
console.log(this.firms[0].name); // works
var a = 0;
console.log("--------------");
data.forEach(function (eachObj) {
console.log("firms check!");
console.log(this.firms); // not working
a = a + eachObj.income;
eachObj.name = this.firms[data.firmid - 1].name; // wont work
});
Fehler:
Cannot read property 'firms' of undefined
Bitte geben Sie uns https://plnrkr.co/edit/ – SjaakvBrabant
Mögliche Duplikate von [Passing scope for forEach] (http://stackoverflow.com/questions/) 19733758/passing-scope-to-foreach) – Erazihel