Encountered an intriguing challenge. Here are the types I'm working with:
export interface QuestionPrimative {
question : string;
id : string;
name : string;
formctrl? : string;
formgrp? : string;
lowExtreme? : string;
hiExtreme? : string;
template : string;
}
export interface Answer {
answer : string;
id : string;
trigger? : string;
formctrl? : string;
}
export interface QuestionBase extends QuestionPrimative {
answers?: Answer[];
}
export interface MicroQuestions {
activate? : string;
questions? : QuestionBase[]; // Prefer this as Question[]
}
export interface Question extends QuestionBase {
micros? : MicroQuestions[];
}
Loading this into a custom Angular 2 Component
designed to handle various types of questions automatically. To provide a clearer explanation and reasoning behind the structure, here is a commented version of the entire model:
// Data iteration in Component
question : string;
id : string;
name : string;
formctrl? : string;
formgrp? : string;
template : string;
answers? : Answer[];
lowExtreme? : string;
hiExtreme? : string;
micros? : MicroQuestions[];
// If answers exist.....
answer : string;
id : string;
trigger? : string;
formctrl? : string;
// If additional questions exist......
activate? : string;
questions? : QuestionBase[];
Any suggestions on how to properly type this for effective looping?