[英]How to populate nested json data to angular material drop down list
This is Json Data........ I have to print difficultyLevel这是 Json 数据........我要打印难度级别
I tried multiple times but thats not working.我尝试了多次,但那不起作用。 what changes are required in html file
html 文件需要进行哪些更改
const ELEMENT_DATA: data = {
questions: [
{
difficultyLevel: 'esay',
isOptionAvailable: true,
isImageAvailable: false,
imageUrl: '',
questionType: 'e',
maximumMarks: 20,
timeToSolve: 12,
questionId: 2,
topicName: 'xs',
classInfo: {
classId: 10,
className: '6',
},
subjectInfo: {
subjectName: 'English',
subjectId: 3,
},
Interface
界面
interface data {
questions: Question[];
message: string;
status: string;
}
interface Question {
difficultyLevel: string;
isOptionAvailable: boolean;
isImageAvailable: boolean;
imageUrl?: string;
questionType: string;
maximumMarks?: number;
timeToSolve: number;
questionId: number;
topicName: string;
classInfo: ClassInfo;
subjectInfo: SubjectInfo;
boardInfo: BoardInfo;
images: any[];
options: Option[];
}
What I'm trying:
我正在尝试什么:
<mat-form-field class="drop-down" appearance="fill">
<mat-label>--Difficulty Level--</mat-label>
<mat-select [(ngModel)]="selectedValue" name="food">
<mat-option *ngFor="let diff of " [value]="diff.questionId">
{{ diff.difficultyLevel }}
</mat-option>
</mat-select>
</mat-form-field>
But this is not working... How to write in mat-option
但这不起作用...如何在 mat-option 中编写
Use the below code to iterate.使用下面的代码进行迭代。
<mat-form-field class="drop-down" appearance="fill">
<mat-label>--Difficulty Level--</mat-label>
<mat-select [(ngModel)]="selectedValue" name="food">
<mat-option *ngFor="let diff of ELEMENT_DATA.questions" [value]="diff.questionId">
{{ diff.difficultyLevel }}
</mat-option>
</mat-select>
</mat-form-field>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.