javascript - Angular 2 Cannot Read Property of Undefined (Function Name) -


this question has answer here:

component:

import { component, oninit } '@angular/core'; import { httpclient } '@angular/common/http';  @component({   selector: 'app-ore-table',   templateurl: './ore-table.component.html',   styleurls: ['./ore-table.component.less'] }) export class oretablecomponent implements oninit {   ores = '../assets/json/ores.json';   prices = 'https://esi.tech.ccp.is/latest/markets/prices/?datasource=tranquility';    orearray: any;   pricesarray: any;   joinedarray: any;    constructor(private http: httpclient) { }    getores() {     this.http.get(this.ores).subscribe(data => {       this.orearray = data;       this.getprices();     });   }    getprices() {     this.http.get(this.prices).subscribe(data => {       this.pricesarray = data;       this.joinprices();     });   }    joinprices() {     this.orearray.foreach(function(data) {       const matchingprice = this.getmatchingprice(data);     });   }    getmatchingprice(data) {     (let = 0; < this.pricesarray.length; i++) {       if (this.pricesarray[i].type_id === data.id) {             return this.pricesarray[i];         }     }     return false;   }    ngoninit() {     this.getores();   } } 

not sure going on here. i'm transferring working code vanilla js angular 2/typescript , getting error when trying run above:

cannot read property 'getmatchingprice' of undefined 

the error occurring on line:

const matchingprice = this.getmatchingprice(data); 

any insight appreciated. thank you.

try instead:

  joinprices() {       this.orearray.foreach((data) => {          const matchingprice = this.getmatchingprice(data);       });    } 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -