Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 我如何解决在应用类型之前需要应用类型的问题';什么是定义?_Angular_Typescript_Typescript2.0 - Fatal编程技术网

Angular 我如何解决在应用类型之前需要应用类型的问题';什么是定义?

Angular 我如何解决在应用类型之前需要应用类型的问题';什么是定义?,angular,typescript,typescript2.0,Angular,Typescript,Typescript2.0,我遇到了一个有趣的问题。这是我的类型 export interface QuestionPrimative { question : string; id : string; name : string; formctrl? : string; formgrp? : string; lowExtreme? : string; hiExtreme? : string; template

我遇到了一个有趣的问题。这是我的类型

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组件中,以自动处理我提出的任何类型的问题。为了更好地说明我在做什么,以及为什么我会以这种方式塑造一切,这里是整个模型的一个注释版本

//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)

有人知道我怎样才能按循环的方式输入它吗?

只要用
问题
替换
问题库
,它就可以正常工作了:

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?: Question[];  // Works
}

export interface Question extends QuestionBase {
  micros?: MicroQuestions[];
}

那么,您是否替换了
问题?:问题库[];//实际上,我希望这是
questions?提出的问题[]
问题[].oh wow,idk我当时做错了什么,因为我之前遇到了一个错误,在《英雄之旅》教程中,他们强调按照使用时已经定义的顺序创建类型,否则数据模型将无法工作。所以我想我已经走进去了,但它起作用了,谢谢。