Within this code snippet, the variable some
is assigned a JSON string that requires expansion and proper indentation for improved readability.
export class MyComponent implements OnInit {
some:any = JSON.parse('[{"id":"EN","fill":"blue","classb":"FR someclass"},{"id":"US","fill":"hsl(240, 100%, 35%)","classb":"someclass"},{"id":"ES","fill":"hsl(240, 100%, 60%)","classb":"someclass"},{"id":"IT","fill":"hsl(240, 100%, 90%)","classb":"someclass"}]');
getStyle(zoneId:string):String{
var test = this.some.find(x => x.id === zoneId);
if( test === undefined) return "#000000";
if( test.fill != undefined) return test.fill;
return "red";
}
}
Is there a way to manage properly indented JSON when initializing TypeScript/Angular class members?