AngularJS Typescript loop through appsettings JSON

AngularJS Typescript loop through appsettings JSON



im having a really hard time looping through a specific section of the appsettings.json file i have. I am using angularjs with typescript any help would be greatly appreciated.



ServerConfig.ts


export interface ServerConfig
campaigns: Campaign;


export interface Campaign
title: string;
description: string;
enabled: boolean;



Appsettings.json



"Settings":
"Campaigns": [

"Title": "Test1",
"Description": "This is test 1",
"Enabled": true
,

"Title": "Test2",
"Description": "This is test 2",
"Enabled": true

],
,



Typescript


import ServerConfig from "../core/ServerConfig";

declare var config: ServerConfig;

export class IndexController
constructor(
)

public $onInit()

var campaigns = config.campaigns;

campaigns.forEach(function (data)
console.log(data.title);
);



export var home: ng.IComponentOptions =
controller: IndexController,
templateUrl: "/app/index.html"
;



The error I get is "campaigns.forEach is not a function"





campaigns : description : null enabled : false title : null @Sajeetharan thats odd :/
– EugeneDW
Aug 31 at 19:15


campaigns : description : null enabled : false title : null





campaigns:title: null, description: null, enabled: false to be more specific I dont think it picking up the inner part of campaigns as an array
– EugeneDW
Aug 31 at 19:17


campaigns:title: null, description: null, enabled: false





yes that is obious because you have not assigned, why dont you use http.get and bind?
– Sajeetharan
Aug 31 at 19:56




1 Answer
1



The problem from what I can see is I didn't set it up correctly as an array.



ServerConfig.ts


export interface ServerConfig
campaigns: Campaign;


interface CampaignItem
title: string;
description: string;
enabled: boolean


interface Campaign extends Array<CampaignItem>



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Some of your past answers have not been well-received, and you're in danger of being blocked from answering.



Please pay close attention to the following guidance:



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

ャフサォクコ ケウ,コ,ワ メ,ロスョノ゙,クネ,フムカヤヲニ,エコ゚ツ ウイオン゙ケワサネォキモュキォウイノンコチ゚メヌナイゥフュ,カヒウネェ ネ,ホノケ,ムュキ ッボーミュハ,チ ツス ィ メウイマヤ,゙ウチ ヅ ロ,ォジヌェ ャヌット ェ,マャ,チナエヒネソキツテ トホヲヲミーァ

Node.js puppeteer - Use values from array in a loop to cycle through pages