The function `getMovie` is not a valid function in the `dataService` causing a

When attempting to utilize a service for retrieving a JSON object, I encountered an error while using the service method:

ERROR TypeError: this.dataService.getMovie is not a function

Here is my code snippet:

DataService:

@Injectable({
  providedIn: 'root'
})
export class DataService {

  getMovieURL = 'http://www.omdbapi.com/?apikey=27f198d0&t=';

  constructor(private http: HttpClient) { }

  getMovie(title: string): Observable<Movie> {
    return this.http.get<Movie>(this.getMovieURL + title);
  }
}

main.ts

export class MainComponent implements OnInit {

  moviesToLoad = ["The Predator","Skyscraper","Avengers: Infinity War","Jurassic World: Fallen Kingdom","Black Panther"];
  moviesArray:Array<Movie>=[];

  constructor(private dataService:DataService) {
    
    for(let i =0; i<this.moviesToLoad.length; i++){
      this.dataService.getMovie(this.moviesToLoad[i]).subscribe(res=> {
        this.moviesArray.push(res);
      })
    }
    
  }

html:

<div *ngFor='let c of moviesArray'>
  
    {{moviesArray.Title}}
  
  </div>

What could be causing this issue?

Answer №1

Realized I forgot to include the service in the app.modules, but everything is working fine now thanks to everyone's help!

Answer №2

Inside the app.module.ts file, the service provider configuration is as follows:

 providers: [
    {
      provide: UserDataService,
      useClass: DataService,
    },
  ],

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

Safari (mac) experiencing issues with loading material icons properly on initial attempt

Upon my initial visit to the website, I noticed that the font appeared distorted. https://i.sstatic.net/BtUxI.png However, when I right-clicked and chose "reload page", the fonts were displayed correctly. https://i.sstatic.net/3XUcA.png This issue seem ...

The component is not responding to list scrolling

Issue with Scroll Functionality in Generic List Component On the main page: <ion-header> <app-generic-menu [leftMenu]="'left-menu'" [rightMenu]="'client-menu'" [isSelectionMode]="isSelectio ...

Create a nested array of subcategories within an array object

Currently, I am working on integrating Django Rest and Angular. The JSON array received from the server includes category and subcategory values. My goal is to organize the data such that each category has its related subcategories stored as an array withi ...

Extracting information from JSON structure

My JSON object response includes a `series` array of objects structured like this: { series: [ { name: 'a', data: [1,2,3] }, { name: 'b', data: [4,5,6] } ] } I am looking to extract the `data` values th ...

Collaborate and apply coding principles across both Android and web platforms

Currently, I am developing a web version for my Android app. Within the app, there are numerous utility files such as a class that formats strings in a specific manner. I am wondering if there is a way to write this functionality once and use it on both ...

Navigating Angular applications using IIS server

I am encountering an issue with my Angular 4 app and a .NET Web API on the same IIS server. The angular app is located in the "/wwwroot/angular/" folder, while the web API is in the "/wwwroot/api/" folder. When I make a request to the web API, it works fin ...

Storing Data in Angular: Tips for Saving Entire Page or Component Data for Future Use

I have developed an Angular 6 application with multiple components that utilize @angular/material's horizontal stepper. Each step within the stepper contains complex forms, some created using template driven forms and others using formgroups. I am loo ...

"Utilizing variadic tuple types to implement the pipe function in TypeScript 4: A step-by-step guide

An illustration from the release notes of TypeScript 4 demonstrates the use of variadic tuple types to eliminate multiple overload definitions. It seems feasible to type the pipe function for any number of arguments. type F<P, R> = (p: P) => R ty ...

Exploring the (*ngFor) Directive to Iterate Through an [object Object]

Attempting to iterate through the array using *ngFor as shown below. let geographicalArea = [{ "_id": "5e77f43e48348935b4571fa7", "name": "Latin America", "employee": { "_id": "5e77c50c4476e734d8b30dc6", "name": "Thomas", ...

What is the best way to find the average within different groups in a JavaScript Array?

I am currently working with the Angular JS framework and have a NodeJS array like this: var arr = [{"object":"Anguille","fct":"Type A","value":"2"},{"object":"Athérine"," ...

What are some ways to utilize TypeScript in incorporating extensions to `koa.Request` packages?

Struggling to utilize both koa-tree-router and koa-bodyparser simultaneously, encountering persistent TypeScript errors: export const userLoggingRouter = new KoaTreeRouter<any, DefaultContext>(); userLoggingRouter.post('/logs/action', (ctx ...

"Flask gets stuck just before returning jsonify, resulting in a lack of output (error message

As a new developer, I have created a page that checks if the user is logged in on load. If the user is logged in, it replaces the login forms with data from the server. However, if the user is not logged in, it displays the login forms and waits for the us ...

Utilize Angular6 and NodeJS to exhibit images stored on a server file system

Successfully uploaded images to a server but struggling to find a tutorial on how to display these images using Angular6 and NodeJS. Any help would be greatly appreciated. Thank you in advance. Edit: After many trials and errors, I was able to retrieve a ...

Tips for preventing LocalStorage data from being overwritten in Angular

I have been working on a scheduler to track tasks completed within a specific timeframe. Whenever I click "STOP," an input field appears where I can enter details about the task I just finished. The start time, end time, and duration of the task are then ...

What is the best way to retrieve a JSON property from a JSON object using PHP?

I have encountered a strange issue that I am unable to resolve. Let me explain the scenario. My Android application is sending JSON data to a php script on my server for processing, and I am currently working on decoding this data. Here is the JSON-Array ...

Determining the name of the currently focused DOM element in Angular2

How can I detect the name of a selected element from a group of select elements on a page? For example: <select (click)="functionDetectName()" name="test1"> <select (click)="functionDetectName()" name="test2"> <select (click)="functionDete ...

Tips for executing a function just one time within a mouseover function in TypeScript

I have a project in Angular 7 where I am displaying a list of places. Whenever I hover over a place, an AJAX function is triggered to save that information in the database. However, I noticed that the AJAX function is being called multiple times when I ho ...

Storing an array in a cookie using Angular 8

Currently, I am utilizing the ngx-cookie-service package. { "user": [ { "id": 109, "name": "name1", "job" : "job name" } ], "token":"xxxx" } this.cookieService.set( 'user_id', ...

ionic issue with ion-refresher

I currently have an ion-refresher implemented on 5 different pages within my application <ion-refresher slot="fixed" (ionRefresh)="refreshActions($event)"> <ion-refresher-content pulling-icon="null" refreshing-spinner="null"> <i ...

What is the best way to convert a list of proxies into a JSON format of proxies?

I currently have a collection of proxy servers: proxies = [ "188.166.78.120:8080", "18.210.69.172:3128", "178.128.166.50:8118" ] However, the library I'm using requires the proxies to be structured in JSON format like this: proxies = { "htt ...