*ngFor is not rendering

I understand that this question is frequently asked, but the usual solutions don't seem to be effective in this case.

Here is my code snippet:

export class CourseReviewFormComponent implements OnInit { 
 form: FormGroup
 questionnaire: string[] = [];
 currentQuestionsValue: string[] = [];

 constructor(private serverData: ServerService) { }
  ngOnInit() {
    this.onGetForm();   
   }

 onGetForm() {
   this.serverData.getData('questionnaire/Student Course Review')
     .subscribe(
        (response: Response) => {
         this.questionnaire = response.json();
         let key = Object.keys(this.questionnaire);
         for (let i = 0; i < key.length; i++) {
           this.currentQuestionsValue.push(this.questionnaire[key[i]].items)
         }
         console.log('current Questions Value', this.currentQuestionsValue);
         },
          (error) => console.log('Form Error:', error)
         )
      }
    }

This is how I've set up my template:

 <form>
  <div *ngFor="let data of currentQuestionsValue">
    <strong> {{ data.sno }}). </strong>
    <span>{{ data.question}}</span>
    <div>
      <label *ngFor="let op of data.options; let i = index">
        <input type="radio" name="option" [value]="i">
        <span>{{ op }}</span>
      </label>
    </div>
  </div>
</form>

Despite successfully logging 'current Value' in the console, the ngFor loop does not display any data when rendered on the page.

Investigating why the ngFor loop isn't functioning as expected.

Answer №1

` section, it is necessary to retrieve the initial element of an array and then loop through its contents, which consist of another array. When working with the `ServerService`, I recommend incorporating intermediary stages to convert an observable in the following manner:
.map(data => data.json())
.map(json => json[0])

Answer №2

Are you in search of this?

iterate through the data in currentQuestionsValue[0]

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Firebase installation unsuccessful with npm, but successful with yarn

λ npm -g install firebase npm ERR! Unexpected end of JSON input while parsing near '...9gwBD9c+ThTWWmNBXcfJZ' npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\2nchy\AppData\Roaming\npm-cache&bs ...

What is the process for sending an HTTP post request with a React/Typescript frontend and a C#/.Net backend?

In the frontend code, there is a user login form that accepts the strings email and password. Using MobX State Management in the userstore, there is an action triggered when the user clicks the login button to submit the strings via HTTP post. @action logi ...

Troubleshooting error handling in Angular 2 and Web API when using Chrome versus Internet Explorer for HTTP PUT requests

Currently, I am working on integrating Angular 2 with Web API in a test project to enhance my skills. However, I have encountered an issue while using the http.put method and would greatly appreciate any insights on this. So far, I have successfully manag ...

Failed validation for Angular file upload

I attempted to create a file validator in the front end using Angular. The validator is quite straightforward. I added a function onFileChange(event) to the file input form to extract properties from the uploaded file. I then implemented a filter - only al ...

An error has occurred in Node.js/Express.js: The path argument is missing and is required for res.sendFile

I have successfully uploaded my files using Multer to a specific directory. However, I am now facing an issue while trying to download the same files that are displayed in an HTML table with individual download options. Below is the code snippet: Node.j ...

Exploring Heroes in Angular 2: Retrieving Object Information by Clicking on <li> Items

Currently, I am delving into the documentation for an angular 4 project called "Tour of Heroes" which can be found at https://angular.io/docs/ts/latest/tutorial/toh-pt2.html. <li *ngFor="let hero of heroes" (click)="onSelect(hero)">{{hero.name}}< ...

Receive Angular error messages in another foreign dialect

If I set up an Angular Reactive form to include validation like this this.formGroup = this._formBuilder.group({ formControl: new FormControl(null, [Validators.required]) }); Which means the input is required. When attempting to submit with a blank inpu ...

What is the importance of moving prop types into a type or interface in React components?

Consider the scenario where I have a functional component: const MyText = ({ value }) => ( <div className="my-fancy-text">{value}</div> ); Now, when utilizing Typescript, I face the need to introduce typing. A straightforward ...

Issue with Ag grid rendering in Angular 2 with webpack 2 configuration not displaying properly

I'm currently attempting to integrate ag-grid into my Angular2 project, but I'm experiencing difficulties with rendering. I'm using the ag-grid package and following a tutorial for a .NET project generated with the command 'dotnet new ...

The custom loader for Webpack (haml-haml-loader) appears to be malfunctioning

I am fairly new to managing my own Angular applications. I found this helpful guide for setting up haml loading through webpack. However, the guide is quite outdated and ngx no longer supports eject, so I am experimenting with this package to customize web ...

Angular - Filtering only ag-Grid information

I am currently working on implementing print functionality for ag-Grid in an angular project. I have a page that includes both content and ag-Grid data. When I attempt to use the print functionality, both the content and grid data are being printed. Howeve ...

Is it possible to create and manage a hierarchical menu in React (Next.js) using a generic approach?

Over the past few days, I've been working on a project involving a navigation bar built with TypeScript and React (Next.js). Up until now, I've only had a single level navigation, but now I'm looking to upgrade to a multi-level navigation me ...

Which is better for scrolling in Angular 2+: using HostListener or window.pageYOffset?

Which syntax is best for maximizing performance in Angular 2+? Is it necessary to use HostListener, or is it simpler to obtain the scroll position using the onscroll window event and pageYOffset? @HostListener('window:scroll', ['$event&ap ...

Angular 14 encountered an unexpected issue: There was an unhandled exception with the script file node_modules/tinymce/themes/modern/theme.min.js missing

After attempting to run ng serve, an error message appears: ⠋ Generating browser application bundles (phase: setup) ...An unhandled exception occurred: Script file node_modules/tinymce/themes/modern/theme.min.js does not exist. ⠋ Generating browser ap ...

Obtain the ViewContainerRef of the AppComponent

Currently, I am searching for a method to obtain the ViewContainerRef of the AppComponent using a service. I have come across various sources online such as this article, this blog post, and this forum thread, but they are all tailored to older versions o ...

Using GSAP in an Ionic application

What is the best way to add the GSAP library to an Ionic project? Simply running npm install gsap doesn't seem to work when I try to import it using: import { TweenMax, TimelineMax} from "gsap"; I am currently using TypeScript. Thank you. ...

What is the benefit of utilizing ngSubmit over just using a basic button and function?

Lately, I've been pondering whether to utilize ngSubmit or simply bind a (click)="submit()" on a button. There's been much debate about using submit and ngSubmit, but is it necessary to rely on the traditional HTML submit method? Particularly wh ...

TypeScript error: Unable to locate namespace 'ng'

I am attempting to utilize a tsconfig.json file in order to avoid having /// <reference tags at the beginning of multiple files. However, I keep encountering this error: [ts] Cannot find namespace 'ng'. any Here is my configuration within ...

Typescript's spellbinding courses

I'm encountering some issues with Typescript and the "@botstan/Magic" library in nodejs. Before we proceed, please take a look at the "Magic" documentation. Follow these lines: import Magic from "@botstan/magic"; import * as _ from "lodash"; @ ...

Improved error messages for anticipated scenarios in Protractor

During my form testing, I utilized ExpectedConditions.and method to verify if all fields display the expected values. expect( await browser.wait( ec.and( ec.textToBePresentInElementValue(edit.driverFirstName, 'te ...