Looking for some assistance as I'm struggling to make this work. My goal is to iterate through an array nested within a config value and then call another function from the service that I built. However, I keep encountering an error:
TypeError: Cannot read property 'registerToken' of undefined
Is there a more efficient way to approach this? The current method seems quite cumbersome.
CampaignService.ts
import { ServerConfig } from "../core/ServerConfig";
declare var config: ServerConfig;
export class CampaignService {
static $inject = ["localStorageService"];
constructor(
public localStorageService: angular.local.storage.ILocalStorageService
) {
}
launchCampaign(campaignToken: string) {
if (campaignToken) {
config.campaigns.forEach(function (data) {
if (campaignToken == data.title) {
if (data.enabled) {
this.registerToken(campaignToken);
}
}
});
}
};
registerToken(campaignToken: string) {
}
}