0
我走进了一个有趣的问题。这里是我的类型如何解决在定义之前需要应用类型的问题?
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[]; // I actually want this to be Question[]
}
export interface Question extends QuestionBase {
micros? : MicroQuestions[];
}
我加载到一个Angular 2 Component
我创造了我的问卷,自动处理问题的任何风格我扔在这。为了让为我做什么更好的例子,为什么我形这里的一切这种方式是整个模型的注释版本
//The data when it iterates into Component
question : string; // the question to be asked
id : string; // id attribute for HTML
name : string; // name attribute for HTML
formctrl? : string; // if element will be a form control
formgrp? : string; // if element will be a form group
template : string; // matches *ngIf on appropriate chunk of HTML
answers? : Answer[]; // available answers if multiple choice
lowExtreme? : string; // low extreme if question involves rating
hiExtreme? : string; // hi extreme for rating
micros? : MicroQuestions[]; // if more questions are available
//if answers are available.....
answer : string; // the answer
id : string; // id attribute for HTML
trigger? : string; // used to trigger another tier of questions
formctrl? : string; // if element needs to be a form control
//if there is another tier of questions ......
activate? : string; // matches with the 'trigger' in the answer to know to load
questions? : QuestionBase[]; // the next tier of questions(which I want to have micros)
有谁知道我可以键入这个在一个循环的工作,它需要的方式至?
好了,你代替'的问题吗? :QuestionBase []; //我真的希望通过问题来解答问题[]? :问题[];'。 –
哦哇,idk我做错了什么,然后因为我之前得到了一个错误,并且有一些熟悉的Heros教程引发了共鸣,他们强调在按照顺序创建类型的位置,否则数据模型将不会被定义,工作。所以我认为我已经走入了这个道路,但它很有用,谢谢。 – Optiq