Issue encountered while constructing Angular application

Throughout the process of developing this application, I have consistently encountered the error message "[ts] ',' expected". Interestingly, adding a comma resolves the issue temporarily, allowing the application to run. However, upon stopping the local server and attempting to run it again, I am required to remove the comma for the app to function properly. As a beginner in learning Angular, I am puzzled by this recurring problem and seek guidance on what I may be doing wrong.

Error Message

ERROR in src/app/breeds/breeds.component.ts(35,5): error TS1005: ',' 
   expected.
   src/app/newbreed/newbreed.component.ts(41,10): error TS1128: Declaration 
   or statement expected.
   src/app/newbreed/newbreed.component.ts(45,1): error TS1128: Declaration 
   or statement expected.

Code

import { Component, OnInit } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { map } from 'rxjs/operators';
import { element } from 'protractor';
import {RequestOptions, Request, RequestMethod} from '@angular/http';

@Component({
  selector: 'app-breeds',
  templateUrl: './breeds.component.html',
  styleUrls: ['./breeds.component.css']
})
export class BreedsComponent implements OnInit {
  restItems: any;
  restItemsUrl = 'https://breeds-a648.restdb.io/rest/dogs';

  constructor(private http: HttpClient) {};

  ngOnInit() {
    this.getRestItems();
  }

  // Read all REST Items
  getRestItems(){
    this.restItemsServiceGetRestItems()
      .subscribe(
        restItems => {
          this.restItems = restItems;
      },
       (err) => console.log(err), () => {
         setTimeout(() => {
           this.getImages();
           this.deleteBreed();
        },0)
      }
    } <<<<<<< This is where it expects ","

  getImages() {
    let breedName = document.querySelectorAll('#breedName');
    breedName.forEach( (el) => {
      let image = document.createElement('IMG');
      this.http.get(`https://pixabay.com/api/?key=&q=${el.innerHTML}&image_type=photo`).subscribe(
        res => {
          image.src = res.hits[0].largeImageURL;
          image.width = '100';
          image.height = '100';
          el.appendChild(document.createElement('br'));
          el.appendChild(image);      
        },
        err => {
          alert("Error occurred");
        }
      );
    })
  }

  deleteBreed() {
    let deleteLinks = document.querySelectorAll('.del');
    deleteLinks.forEach( (e) => {
      e.addEventListener('click', (element) => {
        this.http.delete('https://breeds-a648.restdb.io/rest/dogs' + '/' + element.target.id, { headers: new HttpHeaders()
        .set("x-apikey", "")
        .set("Content-Type", "application/json")
        .set('cache-control', 'no-cache') })
        .subscribe(
          res => {
            window.location.href = '/index';
          },
          err => {
            alert("Error occurred");
          }
        );
      })
    })
  }

  // Rest Items Service: Read all REST Items
  restItemsServiceGetRestItems() {
    const headers = new HttpHeaders()
    .set("x-apikey", "")
    .set("Content-Type", "application/json")
    .set('cache-control', 'no-cache');

    return this.http
      .get<any[]>(this.restItemsUrl,{headers})
      .pipe(map(data => data));
  }

}

Answer №1

Don't forget to add a closing parenthesis in your method:

fetchItemsData(){
    this.itemsServiceFetchItems()
      .subscribe(
        items => {
          this.items = items;
      },
       (error) => console.log(error), () => {
         setTimeout(() => {
           this.showImages();
           this.removeCategory();
        },0)
      }) <- don't forget to close the parentheses here
    }

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

Clearing the Angular cache is necessary every time new changes are added to production mode

Currently, I am working with angular 9.0.3 and after making some new changes, I upload it to Cpanel and compile using the following command: ng build --prod --aot --outputHashing=all --extractCss=true. However, once uploaded, if I visit the website and en ...

What is the best method for hashing CSS module class names in the latest version of Nextjs?

Is there a way to modify/minify/encrypt/conceal/obscure CSS class names in Next JS? I've attempted various methods, including referencing this discussion. Encountering the following issues while experimenting with this proposed solution: yarn bu ...

Disable multiple buttons at once by clicking on them

What is the best way to disable all buttons in a menu when one of them is clicked? Here is my code: <div class="header-menu"> <button type="button"> <i class="fa fa-search" matTooltip="Filter"& ...

Creating Personalized Validators for Angular Version 5 Reactive Forms

I am struggling to create a custom validator for my Angular v5 application. I followed the documentation for a basic password match example in the Docs, but it's not working as expected. this.personalInfoForm = _fb.group({ 'name': [null,V ...

Tips for enhancing the appearance of the dropdown scrollbar in PrimeNG

Just started exploring Angular and I've been struggling to customize the scrollbar on a PrimeNG dropdown. Does anyone have any tips or tricks to achieve this? Here is the HTML code: <p-autoComplete placeholder="- Select -" (onSelect)="onSelect(dh ...

How to detect changes in a variable within a different component using Angular 7

My navbar component includes a dropdown menu that allows users to change the language using ngx/translate: <div class="traduction"> <ul> <li class="nav-item dropdown no-arrow"> <a class="nav-link dropdown ...

Angular2 Firebase: Preflight response contains an invalid HTTP status code 405

I am a beginner with Angular2 and I am facing an issue while trying to retrieve values from the Firebase API. The error I am encountering is as follows: OPTIONS https://udemy-ng-http.firebaseio.com/data 405 (Method Not Allowed) Failed to load https://ude ...

Maximizing Intellisense for custom Javascript services in VS Code using Typescript definitions

While developing a backend server with SailsJS, I encountered an issue where my model helper services and own services were not showing Intellisense. To address this, I set up typings, installed type definitions for lodash and node globally, and created js ...

Detecting changes in a child component using Angular

I recently posed a question on stackoverflow regarding how to control the visibility of a list of objects in Angular. The question was answered, but it led to another inquiry. Now, I am trying to figure out how to have a child component detect when someth ...

What is the process for deciphering HTML elements in TypeScript?

I am currently utilizing Angular 2 alongside C# and SQL Server for my project. One of the scenarios I'm facing involves retrieving an HTML string from the database, which may contain encoded HTML tags or special characters such as (> , <, &, ...

Trying out the results of angular services

Seeking assistance in understanding the current situation: I believe a simple tour of heroes app would be helpful in clarifying, I am looking to set up some tests using Jest to verify if the behavior of a service remains consistent over time. This is ho ...

Issue with Datepicker validation in Angular 5 and Angular Material

I have implemented the most recent version of Angular and Angular Material. I am facing an issue with a datepicker where the validation requirements are not being met as expected. The documentation states that the required attribute should work by default, ...

Using Typescript: Defining a property's type based on the value of another property in the same object

I'm dealing with a TypeScript interface that consists of two properties (type:string and args:object). The contents of the args property may vary based on the value of the type. I'm looking for the correct type definition to specify for the args ...

Angular 7 and Express: No content returned in response body after making a POST request

I am encountering an issue with retrieving the response from a POST request in Angular 7. When I set the API to return "text," everything works as expected. However, when I change the response to JSON, the response body in Angular appears to be null. Test ...

Encountering a TSLint interface error when adding a value to a nested array

Currently, I am transforming responses into an array of Months and Days, with each Day containing an array of numbers. The logic itself is functioning properly, however, I am encountering a tslint error specifically when attempting to push a value into the ...

Navigating Angular to various paths within a single component

I have a landing page for my Angular site at http://example.com/consultation and the routing is set up as follows: The challenge is: when the URL is http://example.com/consultation (with no additional path after consultation), I want to randomly route to ...

What can you create with Angular 4, the angular material 2 library, and angular flex-layout

I am fairly new to visual design and currently using Angular 4 with the Material 2 module and Bootstrap for the grid system. However, I have come to realize that the container sizes are not suitable for certain aspect ratios like 21:9. I discovered the ...

Can Next.js accommodate server-side redirection with internationalization?

I'm working on a small Next.js app that has pages accessible only to logged in users. To manage the authenticated routes, I created an HOC (withAuth) that handles redirection on the server side to prevent page flashing on the client side. Everything i ...

styled components are having issues with background gradients and opacity not functioning properly

Hello, I am currently working with styled components and have the following global style code: const GlobalStyle = createGlobalStyle` html{ font-family: roboto; background: linear-gradient(45deg,rgba(137,255,255,0.5),rgba(161,252,143, 0 ...

What is the process for authenticating and sending a click conversion to Google Ads using a service account and the REST API with TypeScript?

I have attempted to authenticate using this documentation and to send conversions via REST API using this REST endpoint due to the absence of a Typescript/Javascript Client Library. However, I am encountering authentication issues. Once resolved, I aim to ...