Error in parsing: An unexpected symbol appeared, an identifier or keyword was expected at the end of the expression

Whenever I attempt to display data from an API, an error always pops up. My goal is to showcase each piece of data individually. To help you analyze the issue, I've included the URL of the API below:

civilizationes.component.ts

import { Component, OnInit } from '@angular/core';
import { GameService } from '../../services/game.service';

@Component({
  selector: 'app-civilizaciones',
  templateUrl: './civilizaciones.component.html',
  styleUrls: ['./civilizaciones.component.css']
})
export class CivilizacionesComponent implements OnInit {

  civilizaciones: any = [];

  constructor(private gameService: GameService) { }

  ngOnInit() {
    this.gameService.getCivilizations().subscribe(
      res => {
        this.civilizaciones = res;
      },
      err => console.error(err)
    );
  }
}

civilizationes.component.html

<tr *ngFor="let civilizacion of civilizaciones">
    <td>{{civilizacion.name}}</td>
</tr>

API

{
  "civilizations": [
    {
      "id": 1, 
      "name": "Aztecs", 
      "expansion": "The Conquerors", 
      "army_type": "Infantry and Monk", 
      "unique_unit": [
        "https://age-of-empires-2-api.herokuapp.com/api/v1/unit/jaguar_warrior"
      ], 
      "unique_tech": [
        "https://age-of-empires-2-api.herokuapp.com/api/v1/technology/garland_wars"
      ], 
      "team_bonus": "Relics generate +33% gold", 
      "civilization_bonus": [
        "Villagers carry +5", 
        "Military units created 15% faster", 
        "+5 Monk hit points for each Monastery technology", 
        "Loom free"
      ]
    },

https://i.sstatic.net/JmoWe.png

Answer №1

Give it a shot:

<div *ngFor="let civilization of civilizations">
    <span>{{civilization.name}}</span>
</div>

Answer №2

The API's response includes a key called civilizations, so make sure to assign its value, rather than the entire response object.

 ngOnInit() {
    this.gameService.getCivilizations().subscribe(
      data => {
         this.civilizaciones = data.civilizations; 
      },
      error => console.log(error)
    );
  }

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

After using apt to install tsc, I find myself in a dilemma on how to either delete or upgrade it

After realizing I was missing Typescript on my server, I attempted to run the 'tsc' command. However, I received a message suggesting I use 'apt install tsc' instead. Without much thought, I executed the command. Normally, I would insta ...

Making Angular2 Templates More Efficient with Array.prototype.filter()

I have a variable named networkInterface that includes an array called services. My objective is to create a checkbox input that indicates whether a specific service_id exists within the services array of the networkInterface. An illustration of JSON `int ...

Guide to Setting Up Infinite Scroll with Next JS SSG

I recently built a markdown blog using the Next Js documentation and incorporated Typescript. When trying to retrieve a list of blog posts, I utilized getStaticProps as recommended in the documentation. However, my attempts with certain npm packages were u ...

The NgSwitch is behaving unexpectedly, throwing an exception with the message "No provider for NgSwitch"

My HTML code snippet is shown below: <ng-container *ngIf="col.data !== ''"> <ng-template [ngSwitch]="col.data"> <ng-container *ngSwitchCase="'Page'"> <div>{{g ...

Tips for condensing text using ellipsis and Angular-FlexLayout

I am working on a flex row setup that includes three nested flex rows. Within the second row, I need to display a title that should not be shortened, and a text that should be truncated. Additionally, the first and last row must maintain a fixed width with ...

Utilizing feature flags for Angular modules to enable lazy loading

Can we dynamically change the lazy loaded module based on a specific flag? For instance, loading module A if the flag is active and module B otherwise. The crucial aspect is that both modules should use the same path. Approach #1 - dynamic loadChildren() ...

The attribute 'y' is not found within the data type 'number'

Currently working on a project using Vue.js, Quasar, and TypeScript. However, encountering errors that state the following: Property 'y' does not exist on type 'number | { x: number[]; y: number[]; }'. Property 'y' does not ...

Use the CLI to install both the alpha and beta versions of Angular on your system

I'm interested in switching to a version of angular that is currently in active development and testing, like 8.0.0-beta, however I currently have 8.1.0 installed. What is the best way for me to downgrade from version 8.1.0 to 8.0.0-beta? ...

Leveraging async/await in Firebase functions along with the once() method

Recently diving into the world of TypeScript, I've been navigating my way through with relative ease. However, I've encountered a perplexing issue while working with async/await. The problem lies within this code snippet - the 'await' ...

In an Angular Material data table, table headers will always be displayed, even if there is no data

When utilizing the Angular material data table to present product-related information with sorting functionality using matSort, I faced an issue. Even when no data is available, the table headers still remained visible due to the [hidden]="!data" ...

How can one click the button within the expanded dropdown while hovering over the navigation item in Angular and Bootstrap?

Issue Description: Upon hovering over a navigation item, the dropdown container is displayed but it's not clickable. Desired Behavior: Hovering over a navigation item should display the dropdown container and allow clicking on its contents. Furthermo ...

Angular 4 - Automatically scroll to specific list item based on search query input

While I can achieve this with custom JavaScript, I'm curious if Angular 4 has any built-in features that could help. I have a list of checkboxes that are scrollable and a search input above them. My goal is to enable users to quickly jump to a section ...

Issue with angular oidc-client library's automaticSilentRenew functionality

I'm currently implementing oidc authentication using "oidc-client" version 1.10.1. Below is the configuration I have set up for the userManager: const settings = { authority: (window as any).__env.auth.authority, //OAuth 2.0 authorization end ...

Tips for creating an interface in TypeScript that prevents access to uninitialized properties of a class

Interfaces still baffle me a bit. I understand that interfaces are typically used for public properties, but I want to create an interface that will prevent access to uninitialized properties. Currently, I am able to access this.material without any errors ...

How to activate the close function of ionic-datepicker when tapping the hardware back button in Ionic 4

Utilizing ionic-datepicker in my app (ionic v-4), here is the corresponding template: <ion-datetime formControlName="meeting_date" display-format="MMM DD, YYYY"></ion-datetime> The datepicker (i.e ion-datetime) closes upon clicking cancel/do ...

Error shown in console when using Angular 7 FormControlName

My webpage has a reactive form, but I keep encountering an error message that states: ERROR Error: formControlName must be used with a parent formGroup directive. Make sure to include a formGroup directive and pass it an existing FormGroup instance (you ...

There seems to be an issue with the useReducer value not updating when logging it in a handleSubmit function

I'm currently incorporating useReducer into my Login and Register form. Interestingly, when I attempt to log the reducer value, it only displays the default value. However, if I log it within the useEffect hook, it functions correctly. Below is a sn ...

Where does the injected style in the Angular build index file originate from?

I recently completed the migration of my Angular application from v7 to v12. I have a custom index file specified in my angular.json file like so... "projects": { "routes": { "architect": { "build": { ...

Enabling and disabling contenteditable functionality on a div element in Angular

Issue I am facing an issue while trying to bind a boolean to the contenteditable directive of a div. However, it seems that this binding is not working as expected. Error Message: The 'contenteditable' property is not recognized as a valid p ...

What is causing the geolocation heading to remain "null" on Android devices when using Chrome?

Recently, I developed a compact geolocation watch using the following code snippet: navigator.geolocation.watchPosition( this.updateLocation.bind(this), this.errorLocation.bind(this), {enableHighAccuracy: true} ); The function updateLocation ...